user3421904
user3421904

Reputation:

join with where Vs join keyword in SQL

For joining tables I have always used the following approach:

Select e.name, e.surname, sum(s.gross) as sum_gross, AVG(s.gross) as avg_gross
from departments d
    join employees e
        on d.depid = e.depid
    join salaries s 
        on e.employeeid = s.personid
    group by e.name,e.surname

But now I saw some people who do it in the following way:

Select e.name, e.surname, sum(s.gross) as sum_gross, AVG(s.gross) as avg_gross
from departments d, employees e, salaries s
where d.depit = e.depid
and e.employeeid = s.personid
group by e.name,e.surname

I just want to make sure they are exactly the same and which one is preferred and is the best practice?

Upvotes: 1

Views: 34

Answers (1)

Vincent Savard
Vincent Savard

Reputation: 35927

They produce the same execution plan. The first query is the preferred syntax since the SQL-92 revision.

Upvotes: 1

Related Questions