Board index » delphi » Outer Join SQL

Outer Join SQL

Please help with some SQL...

Having a problem figuring out the "outer join" syntax for Sybase Anywhere
(local version of Sybase SQL Server).  Syntax should be the same for both I
guess.

Anyway, when joining a 2nd table with an "=", I use "*=" and this works
fine.

But, when joining a 2nd table based on ">=" or ">" or "<", I can not figure
out the correct syntax.

Any comments are welcome.  Is this outer join even possible?

Keith

 

Re:Outer Join SQL


Imagine you have two tables tab_a and tab_b

select *
from tab_a, tab_b
where
  tab_a.some_field >= tab_b.inicial_value and
  tab_a.some_field <= tab_b.final_value

Imagine the range tab_b.initial_value to tab_b.final_value can contain a 1000000 records. What you expect using an outer join? You
want to receive one milion lines with the same tab_a record and nulls for the tab_b?

Outer joins returns the row if it exists. If not, returns null. If you request all record with an int field >= 0 you will receive
2^31 records not found as nulls?

I think it is not possible...

[]s
Arthur

kdw <kdw...@erols.com> escreveu nas notcias de mensagem:95sa0q$i...@bornews.inprise.com...

Quote
> Please help with some SQL...

> Having a problem figuring out the "outer join" syntax for Sybase Anywhere
> (local version of Sybase SQL Server).  Syntax should be the same for both I
> guess.

> Anyway, when joining a 2nd table with an "=", I use "*=" and this works
> fine.

> But, when joining a 2nd table based on ">=" or ">" or "<", I can not figure
> out the correct syntax.

> Any comments are welcome.  Is this outer join even possible?

> Keith

Re:Outer Join SQL


Have you tried performing your joins in the FROM clause?  I haven't done a
join using Transact-SQL syntax for a long time, mainly because I find it so
much easier to perform the join using JOIN syntax in the FROM clause. You
should be able to find all of the info you need in the SQL Anywhere
documentation.

I must confess I don't quite understand what you are actually trying to do,
so it's hard to suggest an alternative approach.  Can you post a sample of
the query you are trying to execute?

Quote
"kdw" <kdw...@erols.com> wrote in message

news:95sa0q$ioo1@bornews.inprise.com...
Quote
> Please help with some SQL...

> Having a problem figuring out the "outer join" syntax for Sybase Anywhere
> (local version of Sybase SQL Server).  Syntax should be the same for both
I
> guess.

> Anyway, when joining a 2nd table with an "=", I use "*=" and this works
> fine.

> But, when joining a 2nd table based on ">=" or ">" or "<", I can not
figure
> out the correct syntax.

> Any comments are welcome.  Is this outer join even possible?

> Keith

Re:Outer Join SQL


it's been 3 years since I used this but to the best of my memory you can use
the following syntax

select a,b,c
from table1 left outer join table2 on (table1.a =table2.a)
...

you can user RIGHT or FULLl instead of LEFT.  I think this is in the help file
that usually installed in the sqlany50 directory (or sybase dir).

Of course my memory could be playing tricks on me :-) 34 and can't remember my
own birthday without thought,  guess it's all down hill from here......

mike h.

Quote
kdw wrote:
> Please help with some SQL...

> Having a problem figuring out the "outer join" syntax for Sybase Anywhere
> (local version of Sybase SQL Server).  Syntax should be the same for both I
> guess.

> Anyway, when joining a 2nd table with an "=", I use "*=" and this works
> fine.

> But, when joining a 2nd table based on ">=" or ">" or "<", I can not figure
> out the correct syntax.

> Any comments are welcome.  Is this outer join even possible?

> Keith

Re:Outer Join SQL


Don't use *= type of joins. It is much easier, more clear and much more
flexible with LEFT/RIGHT OUTER JOIN.

select a.*, b.*, c.*
from table1 a
left outer join table2 b on a.code = b.code
inner join table3 c on b.amount >= c.amount

rb

Other Threads