Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
hi guys, i have a issue with sql, that is when we use "select", i think there're always 2 methods ,
SQL
select 
 name.t1,name.t2,name.t3 
from 
 t1,t2,t3 
where 
 t1.id=t2.id and t2.id=t3.id

or
SQL
select 
 name.t1,name.t2, name.t3 
from 
 t1
inner join t2 on t1.id=t2.id 
inner join t3 on t2.id=t3.id


so,
1.what's the differences between the 2 methods of select ?

2.if we use the 1st method, in oracle, we can use(+) to achieve left or right join, but in sql server or mysql or mb other database, how can we achieve left join in using the 1st method?

thanks in advance!
Posted

You have some wrong syntax here. It should be like table.Coluumn not column.table

SQL
select
 t1.name,t2.name,t3.name
from
 t1,t2,t3
where
 t1.id=t2.id and t2.id=t3.id


Ans1: The first one is short hand(also the old method) so doing this while later one is the detailed way and much readable.

Ans2:
SQL
select t1.name,t2.name,t3.name
from t1
 left join t2 on t1.id=t2.id
 left join t3 on t2.id=t3.id
 
Share this answer
 
Comments
v03051435 31-Mar-14 8:52am    
hi,Goel, thanks for ur reply, if i wanna use short hand and left join in the same time, how to achieve? like "Where a.col1 *= b.col1"? and there is no influence of matenance between "short hand" and "writing left join each time" method? thanks for ur reply.
Er. Puneet Goel 31-Mar-14 8:56am    
this is simple

select a.name,b.name,c.name
from table1 a
left join table2 b on a.id=b.id where b.name = 'abc'
left join table3 c on b.id=c.id where c.name = 'abc'
Where a.name='axyz'
To use left outer join in short hand mode, try using * symbol.
E.g. Where a.col1 *= b.col1
 
Share this answer
 
Comments
v03051435 1-Apr-14 4:05am    
thanks Abhinav, i have another question, what's the diff between :
select t1.name,t2.name,t3.name
from t1
left join t2 on t1.id=t2.id
(and/where) t2.name='aa'
i noticed that "and or where" make different result, so what's the difference? thank you
Abhinav S 1-Apr-14 4:16am    
And adds two sets of conditions. Where is to indicate filters on the table.

Abhinav S 1-Apr-14 4:16am    
Vote if this answer helped.
v03051435 1-Apr-14 5:28am    
thanx for ur reply and i voted, but i found a better answer too for u :

http://stackoverflow.com/questions/354070/sql-join-where-clause-vs-on-clause

that's what i mean :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900