2

I've come from a Postgres/MySQL world, so am wondering if there's a difference between these 2 queries in SQL server:

SELECT e.employee_id, s.salary
FROM employees e INNER JOIN salaries s
ON e.employee_id = s.employee_id


SELECT e.employee_id, s.salary
FROM employees e, salaries s
WHERE e.employee_id = s.employee_id
Henley
  • 21,258
  • 32
  • 119
  • 207
  • 2
    The second is an older syntax, called an implicit join. The first is the modern, preferred explicit join syntax. They are functionally the same – Michael Berkowski Nov 18 '13 at 21:10
  • Postgres and MySQL (and Oracle and DB2 and Firebird and ...) support exactly the same type of joins. That is nothing special to SQL Server (but do stick with the explicit joins) –  Nov 18 '13 at 21:15
  • Hmm.. guess I'm old school b/c I've always been accustomed to the 2nd one. I find it hard to kick old habits so I'm sticking with the 2nd as long as I can get away with it. – Henley Nov 18 '13 at 21:32

4 Answers4

3

The new join syntax was introduced with SQL-92 and is supported by SQL Server (at least as far back as SQL Server 2000) and most other DBMSs these days. Performance wise, they are equivalent, but generally I recommend the new SQL-92 syntax for new code.

Michael Goldshteyn
  • 71,784
  • 24
  • 131
  • 181
1

There is no functional difference between the two. The latter (known as implicit join) is considered outdated, and is usually frowned upon.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

These should do the same exact thing. The first one is the preferred syntax as it is an explicit join and can make your code easier to read!

intA
  • 2,513
  • 12
  • 41
  • 66
0

Like told by Michael Berkowski, the result is the same. The second one is an older approach

Hache
  • 449
  • 3
  • 7