If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > question of syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-08-10, 03:29
bchanan bchanan is offline
Registered User
 
Join Date: Dec 2009
Posts: 27
question of syntax

Hello All,

I often see this syntax:

SELECT a.col1, b.col2, c.col3
FROM table1 a
INNER JOIN table2 b ON a.col1 = b.col2
INNER JOIN table3 c ON b.col2 = c.col3
WHERE a.col1 = 147

while some are writing:

select a.col1, b.col2, c.col3
from table1 as a,
table2 as b,
table3 as c
where a.col1 = b.col2
and b.col2 = c.col3
and a.col1 = 147

Q1: are there any diffrences ? why should i prefer one syntax above the other ?
Q2: assume this is the query, should this bring better results:

select a.col1, b.col2, c.col3
from table1 as a,
table2 as b,
table3 as c
where a.col1 = 147
and b.col2 = 147
and c.col3 = 147

thanks
Chanan
Reply With Quote
  #2 (permalink)  
Old 11-08-10, 04:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Q1. yes there are differences

when they are inner joins, the results produced are the same, although the query with INNER JOINs is a lot easier to understand than the one with the old style comma joins

however, when you need an outer join, the old style comma joins just cannot accomplish it

Q2. no, same results
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On