Best strategy in SQL
https://softwareengineering.stackexchange.com/questions/196890
문제
Recently, a colleague told me that it wasn't advisable to make conditions in the join clauses. Instead he suggested to make conditions in the where clause. He told me that the SQL engine was optimized for this way.
Here is a simple example to illustrate my question. In this case, I think it would make any difference.
What strategy is the best? And why?
Assume we have a parameter nammed @user_id
.
First strategy
SELECT role.name
FROM user_role
INNER JOIN user ON user_role.user_id = user.id AND
user_role.user_id = @user_id
INNER JOIN role ON user_role.role_id = role.id
Second strategy
SELECT role.name
FROM user_role
INNER JOIN user ON user_role.user_id = user.id
INNER JOIN role ON user_role.role_id = role.id
WHERE user.id = @user_id
올바른 솔루션이 없습니다
제휴하지 않습니다 softwareengineering.stackexchange