![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi Faculties, * * I have two queries which give me the same output. * *-- Query 1 * *SELECT prod.name, cat.name * *FROM products prod INNER JOIN categories cat * * * *ON prod.category_id = cat.id * *WHERE cat.id = 1; * -- Query 2 * *SELECT prod.name, cat.name * *FROM products prod INNER JOIN categories cat * * * *ON prod.category_id = cat.id AND cat.id = 1; * The first query uses the WHERE clause and the second one has all the conditions in the ON clause. Is there anthing wrong with the second approach in terms of performance? Please suggest. Thanks in advance Jackal |
#3
| |||
| |||
|
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Hi Faculties, I have two queries which give me the same output. -- Query 1 SELECT prod.name, cat.name FROM products prod INNER JOIN categories cat ON prod.category_id = cat.id WHERE cat.id = 1; -- Query 2 SELECT prod.name, cat.name FROM products prod INNER JOIN categories cat ON prod.category_id = cat.id AND cat.id = 1; The first query uses the WHERE clause and the second one has all the conditions in the ON clause. Is there anthing wrong with the second approach in terms of performance? Please suggest. |
#6
| |||
| |||
|
|
SELECT P.product_name, C.foobar_category FROM Products AS P, VagueCategories AS C WHERE P.foobar_category = C.foobar_category AND C. foobar_category = 1; |
#7
| |||
| |||
|
|
SELECT P.product_name, C.foobar_category FROM Products AS P, VagueCategories AS C WHERE P.foobar_category = C.foobar_category AND C. foobar_category = 1; In SQL Server nobody uses that format any more in fact you'll confuse most developers and leave yourself open to a cartesian product problem which was common before we start using the ANSI 92 introduced INNER JOIN syntax. Best practice definied in Books Online is to use INNER JOIN instead of the prehistoric ANSI 89 style. |
![]() |
| Thread Tools | |
| Display Modes | |
| |