Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

which SQL query choose?

I want to know if is possible if this kind of make queries has a name and which is the better option?

OPTION 1

select * from users, tasks
where users.id = tasks.user_id
and user.name='Lucas'

OPTION 2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT * from task
where user_id in (select id in users where user.name='Lucas')

OPTION 3

SELECT * 
FROM tasks
JOIN users
ON tasks.user_id = users.Id
where user.name='Lucas'

Thanks

>Solution :

When joining tables, I usually go with the join. (OPTION 3 here)

Performance-wise, I don’t think there is much difference between options 1 and 3. As for the 2nd option, I’d avoid it in almost every scenario.

I think this post answers your question in more details.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading