Is this 2 query different? Im getting different results in Oracle SQL, can you explain the difference?
***First Query***
SELECT *
FROM
TABLE1,
TABLE2
WHERE TABLE1.COL_ID = TABLE2.COL_ID
AND TABLE1.COL1 = 'ABC'
AND TABLE2.COL1 = 'ABC'
AND TABLE1.COL2 = 2015
AND TABLE1.COL3 = 'X';
***Second Query***
SELECT *
FROM
TABLE1,
TABLE2,
TABLE3
WHERE TABLE1.COL_ID = TABLE2.COL_ID
AND TABLE1.COL1 = 'ABC'
AND TABLE2.COL1 = 'ABC'
AND TABLE1.COL2 = 2015
AND TABLE1.COL3 = 'X';
Yes, the SQL processor assumes that you are implying a
JOIN
all three tables:table1,table2,table3
You are not required to explicitly state a
join
clause, if you don't the SQL engine will handle it.When you use a comma to separate two (or more) table names what you are intending is the cartesian product. Every row of the 'left' table will be 'matched' (concatenated) with that of the right table.
Now if you write something in the where clause, it's like putting a condition on this 'concatenation' telling which rows to 'concatenate' with which rows.
This is actually "joining" the rows :) and hence the join keyword that helps provide a more readable syntax and is more understandable that you 'indeed' want to join on some common values.