Home > Enterprise >  which SQL query choose?
which SQL query choose?

Time:05-17

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

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

CodePudding user response:

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.

  • Related