选择哪个 SQL 查询?
which SQL query choose?
我想知道这种 make queries 是否可以有一个名字,哪个是更好的选择?
选项 1
select * from users, tasks
where users.id = tasks.user_id
and user.name='Lucas'
选项 2
SELECT * from task
where user_id in (select id in users where user.name='Lucas')
选项 3
SELECT *
FROM tasks
JOIN users
ON tasks.user_id = users.Id
where user.name='Lucas'
谢谢
连接表时,我通常使用连接。 (此处为选项 3)
Performance-wise,我认为选项1和选项3之间没有太大区别。至于选项2,我几乎在所有情况下都会避免它。
我认为 this post 更详细地回答了您的问题。
我想知道这种 make queries 是否可以有一个名字,哪个是更好的选择?
选项 1
select * from users, tasks
where users.id = tasks.user_id
and user.name='Lucas'
选项 2
SELECT * from task
where user_id in (select id in users where user.name='Lucas')
选项 3
SELECT *
FROM tasks
JOIN users
ON tasks.user_id = users.Id
where user.name='Lucas'
谢谢
连接表时,我通常使用连接。 (此处为选项 3)
Performance-wise,我认为选项1和选项3之间没有太大区别。至于选项2,我几乎在所有情况下都会避免它。
我认为 this post 更详细地回答了您的问题。