Friday, March 23, 2012

joins

Hi Friends
I need ur advise on this one.
when writing sql statements and whenever there is need to join 2 or more tables am used to the following syntax (using WHERE to join tables)

select a.name,b.code from table a,table b where a.code=b.code

as you all know we can also use INNER JOINS,OUTER JOINS etc., to join tables and all BOL help example contains this type of syntax.

my question is , am having difficulty using/writing this syntax in my queries .meaning uysing left joins,inner joins in the same queries.I appreciate if u guys can direct me to some good articles or that sort of thing to improve my understanding of this type of syntax.
Thanks

Hi,

IMHO, the information you need is in BOL. As you have mentioned, it contains samples perjorming JOIN querries. All you have to do is experiment with it to get the idea behind it. Use Query Analyzer to achieve this.

cheers,

Paul June A. Domag

|||

See if these help:

--inner join
select a.name,b.code
from table a inner join table b on a.code=b.code

--left join
select a.name,b.code
from table a left join table b on a.code=b.code

--right join
select a.name,b.code
from table a right join table b on a.code=b.code

--full join
select a.name,b.code
from table a full join table b on a.code=b.code

--cross join
select a.name,b.code
from table a cross join table b

|||See if this helps:
http://www.firstsql.com/tutor.htm and especially this http://www.firstsql.com/tutor3.htm#join
--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. (http://www.sqlpass.de)
|||Thanks Frank.That helps mate Smile|||

Hi Paul

Seems like you are very helpful.........

Please assist.

i have several document groups in a table which data i want to export. my statement is: select * from docs_indexed where di_doc_group = 71. this is working and i get the correct results. problem is, i have 350 doc_groups. how do i create a query where i can get results for all the doc_groups in one query?

Regards

Hannes

No comments:

Post a Comment