在SQL中加入Vs join关键字

时间:2014-05-08 03:22:12

标签: mysql sql

对于连接表,我总是使用以下方法:

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

但现在我看到一些人以下列方式做到了这一点:

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

我只想确保它们完全相同,哪一个是首选,是最佳做法?

1 个答案:

答案 0 :(得分:1)

他们制定相同的执行计划。第一个查询是自SQL-92 revision以来的首选语法。