1

Are these 2 queries the same?

Query #1

select 
    e.last_name, e.first_name, d.department_name, l.city
from 
    employees e
inner 
    join departments d on e.department_id = d.department_id
inner join  
    locations l on  d.location_id = l.location_id;

Query #2

select 
    e.last_name, e.first_name, d.department_name, l.city
from 
    employees e, departments d, locations l
where 
    e.department_id = d.department_id 
    AND d.location_id = l.location_id;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 5
    Query #2 is **deprecated** and **should not** be used - see: [Bad habits to kick : using old-style JOINs](https://sqlblog.org/2009/10/08/bad-habits-to-kick-using-old-style-joins) - that old-style *comma-separated list of tables* style was replaced with the *proper* ANSI `JOIN` syntax in the ANSI-**92** SQL Standard (**more than 20 years** ago) and its use is discouraged – marc_s Mar 28 '15 at 08:06
  • Using SSMS you can examine the execution plan to identify similarities and differences. – Sam Axe Mar 28 '15 at 08:32
  • In terms of the data they return and the execution plan, these two queries are same. – Kshitij Mar 28 '15 at 08:57

1 Answers1

0

The two queries might return the same data - but the #2 query uses the old, deprecated style of a comma-separated list of tables. Don't do this - use the proper ANSI JOIN syntax of query #1 instead.

The comma-separated list of tables style was replaced with the proper ANSI JOIN syntax in the ANSI-92 SQL Standard (more than 20 years ago) and its use is discouraged. Stick to query #1 style.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459