I’ve been looking far and wide, but I can’t find an answer, probably because I can’t figure out the right way to ask the question. So here it is: is there any reason to prefer any of these two queries?
SELECT * FROM table1, table2 WHERE table1.id = table2.id;
and
SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;
The question stems from a much more complicated query that I am trying to optimize, but I think those two queries contain the essence of the question, and hopefully by asking in this way it will be more useful to others. Thanks in advance.
and
will return the same results. However you should prefer the second one in this case. The first form is still widely encountered because Oracle did not support the second form for a long time.
Yet, stating
INNER JOINcarries intent and forces you to write a condition because anINNER JOINrequires anONclause. For larger queries it makes the query far more readable and makes it harder to skip a joining predicate.Also, note that I would tend to read the first form as: take the cartesian product of the two tables, and only retain rows that have equal ids in both tables which in SQL is expressed as
SELECT * FROM table1 CROSS JOIN table2 WHERE table1.id = table2.id;.