Gublooo
Gublooo

Reputation: 2618

Are these SQL queries identical - if not whats the difference

Assuming the proper tables are in place - what is the difference between the two queries - when would they return different results

select *
from quiz_user qu
join quiz_topic qt on qu.quiz_id = qt.quiz_id and qt.topic_id=44
where qu.user_id=9

select *
from quiz_user qu
join quiz_topic qt on qu.quiz_id = qt.quiz_id 
where qu.user_id=9
and qt.topic_id=44

Thanks

Upvotes: 1

Views: 99

Answers (2)

Michael Buen
Michael Buen

Reputation: 39393

None, but the second code's intent is clearer, JOIN is merely used to reflect the data relationship, not for filtering.

On first code's JOIN, it would seem the number 44 has a bearing on quiz_topic's relationship to quiz_user

Upvotes: 2

a1ex07
a1ex07

Reputation: 37364

I don't see any difference in queries as they are. However, if you used LEFT JOIN instead of INNER (default), results would be different.

Upvotes: 3

Related Questions