Click here to Skip to main content
15,903,175 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL Server AND Access Pin
theJazzyBrain17-Apr-03 2:45
theJazzyBrain17-Apr-03 2:45 
GeneralSQL server: Updating a table from itself... Pin
Member 9616-Apr-03 10:57
Member 9616-Apr-03 10:57 
GeneralRe: SQL server: Updating a table from itself... Pin
DiWa16-Apr-03 21:49
DiWa16-Apr-03 21:49 
GeneralRe: SQL server: Updating a table from itself... Pin
Member 9617-Apr-03 6:07
Member 9617-Apr-03 6:07 
GeneralINNER JOIN and regular joins Pin
Reno Tiko16-Apr-03 10:07
Reno Tiko16-Apr-03 10:07 
GeneralRe: INNER JOIN and regular joins Pin
Member 9616-Apr-03 10:47
Member 9616-Apr-03 10:47 
GeneralRe: INNER JOIN and regular joins Pin
Bruce Duncan16-Apr-03 19:31
Bruce Duncan16-Apr-03 19:31 
GeneralRe: INNER JOIN and regular joins Pin
Richard Deeming16-Apr-03 23:26
mveRichard Deeming16-Apr-03 23:26 
From SQL Books Online:

Specifying Joins in FROM or WHERE Clauses
The rows selected by a query are filtered first by the FROM clause join conditions, then the WHERE clause search conditions, and then the HAVING clause search conditions. Inner joins can be specified in either the FROM or WHERE clause without affecting the final result.

Outer join conditions, however, may interact differently with the WHERE clause search conditions, depending on whether the join conditions are in the FROM or WHERE clause. Therefore, the ability to specify Transact-SQL outer joins in the WHERE clause is not recommended, is no longer documented, and will be dropped in a future release.

For example, these queries both specify a left outer join to SELECT 23 rows that display the title identification number, title name, and the number of books sold:
-- Join in WHERE clause.
USE pubs
SELECT t.title_id, t.title, s.qty
FROM titles AS t, sales AS s
WHERE t.title_id *= s.title_id

-- Join in FROM clause.
USE pubs
SELECT t.title_id, t.title, s.qty
FROM titles AS t LEFT OUTER JOIN sales AS s
   ON t.title_id = s.title_id

In this query, a search condition is also specified in the WHERE clause:
-- Join and search condition in WHERE clause.
USE pubs
SELECT t.title_id, t.title, s.qty
FROM titles AS t, sales AS s
WHERE t.title_id *= s.title_id
   AND s.stor_id = '7066'

The condition stor_id = '7066' is evaluated along with the join. The join only selects the rows for stor_id 7066 from the sales table, but because it is an outer join null values are supplied as the store information in all the other rows. This query returns 18 rows.

The join condition can be moved to the FROM clause, and the stor_id condition left in the WHERE clause:
USE pubs
SELECT t.title_id, t.title, s.qty
FROM titles AS t LEFT OUTER JOIN sales AS s
   ON t.title_id = s.title_id
WHERE s.stor_id = '7066'

This query returns only two rows because the restriction of stor_id = '7066' is applied after the left outer join has been performed. This eliminates all the rows from the outer join that have NULL for their stor_id. To return the same information with the join condition in the FROM clause, specify the stor_id = '7066' condition as part of the ON join_criteria section in the FROM clause and remove the WHERE clause:
USE pubs
SELECT t.title_id, t.title, s.qty
FROM titles AS t LEFT OUTER JOIN sales AS s
   ON t.title_id = s.title_id 
   AND s.stor_id = '7066'



"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
GeneralStarting MSDE on Win9x Pin
Diego Mijelshon16-Apr-03 9:31
Diego Mijelshon16-Apr-03 9:31 
GeneralPassing DB Name As SProc Parameter Pin
perlmunger16-Apr-03 5:34
perlmunger16-Apr-03 5:34 
GeneralSQL query Pin
John-theKing16-Apr-03 2:02
John-theKing16-Apr-03 2:02 
GeneralRe: SQL query Pin
John Honan16-Apr-03 3:55
John Honan16-Apr-03 3:55 
GeneralRe: SQL query Pin
John-thKing16-Apr-03 4:48
sussJohn-thKing16-Apr-03 4:48 
GeneralRe: SQL query Pin
John Honan16-Apr-03 4:54
John Honan16-Apr-03 4:54 
GeneralRe: SQL query Pin
greg lynch _nj_17-Apr-03 3:07
greg lynch _nj_17-Apr-03 3:07 
GeneralRe: SQL query Pin
si_6917-Apr-03 5:08
si_6917-Apr-03 5:08 
GeneralDummies guide to SQL Pin
Michael P Butler15-Apr-03 23:14
Michael P Butler15-Apr-03 23:14 
GeneralRe: Dummies guide to SQL Pin
perlmunger16-Apr-03 5:44
perlmunger16-Apr-03 5:44 
Generalfield=field+', ' in SQL Pin
stefan b15-Apr-03 23:08
stefan b15-Apr-03 23:08 
GeneralRe: field=field+', ' in SQL Pin
Jeremy Oldham16-Apr-03 2:29
Jeremy Oldham16-Apr-03 2:29 
GeneralRe: field=field+', ' in SQL Pin
stefan b16-Apr-03 18:47
stefan b16-Apr-03 18:47 
GeneralSQL 2000 Backup to SQL 7 Backup Pin
Paul Watson15-Apr-03 22:10
sitebuilderPaul Watson15-Apr-03 22:10 
GeneralRe: SQL 2000 Backup to SQL 7 Backup Pin
Paul Watson15-Apr-03 22:57
sitebuilderPaul Watson15-Apr-03 22:57 
GeneralUpdating Multiple records through Storedprocedure and getting event notifications Pin
Mairaj Zeb15-Apr-03 20:42
Mairaj Zeb15-Apr-03 20:42 
Generaldata mining Pin
devvvy15-Apr-03 16:58
devvvy15-Apr-03 16:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.