You are here: Re: Help With Syntax « MsSQL Server « IT news, forums, messages
Re: Help With Syntax

Posted by SQL Menace on 10/02/84 11:51

be carefull with NULLS and IN, if tableB has even 1 NULL for the
client_id column nothing will be returned
better to add IS NOT NULL

SELECT * FROM tableA WHERE client_id NOT IN (SELECT client_id FROM
tableB WHERE client_id IS NOT NULL )

or use NOT EXISTS

SELECT * FROM tableA A WHERE NOT EXISTS (SELECT * FROM
tableB WHERE client_id = A.client_id )


Denis the SQL Menace
http://sqlservercode.blogspot.com/


Jason wrote:
> Try one of these:
>
> SELECT * FROM tableA WHERE client_id NOT IN (SELECT client_id FROM
> tableB)
>
> SELECT a.*
> FROM tableA a
> LEFT JOIN tableB b ON a.client_id = b.client_id
> WHERE b.client_id IS NULL
>
> you should see better performance on the second one if you have a lot
> of rows in your tables.
>
> Jason

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация