Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
SQL is a declarative language, and the form of the query does not dictate the form of the query plan that actually retrieves the data. So these two queries might be not only the same speed, but act...
Answer
#1: Initial revision
SQL is a declarative language, and the form of the query does not dictate the form of the query plan that actually retrieves the data. So these two queries might be not only the same speed, but actually map to the exact same query plan to be executed. So if speed and results don't give an advantage to one form, the best practice is to go with the one that is easier to read. In this case, I'd go with the first one. In the second query, the JOIN handles both joining and filtering the data. By using a separate WHERE clause, you separate the actions of joining and filtering into different clauses. If a second filter needs to be added later, it's a little less intuitive to add it to the JOIN. It's possible a later developer might create a WHERE clause, and then you'd have the JOIN filtering and joining, and the WHERE filtering as well. But if you're already using a WHERE for filtering, it's simple and intuitive to add another condition to the WHERE.