Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql to select records that are not include on a specific table. 2

Status
Not open for further replies.

jonasggg

Technical User
Sep 30, 2003
12
0
0
UY
Hello.

I would like to select records that are not include on a table. For example, a Client ID that is not included on an invoice table, etc. Can I use Count function?

Thanks in advace.
 
Select * from clients where clientid not in (select clientid from invoice)
 
Select ClientID
From table1
Where NOT EXISTS( Select * From Invoice )
 
jbenson, how can the "exists" work without the inner query being corealated?

Dont you mean


Select ClientID
From table1
Where NOT EXISTS( Select * From Invoice [red]where invoice.invoiceid <> table1.invoiceid[/red] )
 
cRAP@! I mean

Select ClientID
From table1
Where NOT EXISTS( Select * From Invoice where invoice.invoiceid [red]=[/red] table1.invoiceid )
 
For instance
Code:
use pubs
go
select * from titles t where not exists 
(select * from sales where t.title_id = sales.title_id)

returns the two rows that reflect books that havn't sold

but
Code:
use pubs
go
select * from titles t where not exists 
(select * from sales)
Returns no rows..

 
Actually I made a mistake. Typed too quickly, I was just about to post the same answer you had using the IN clause. However your second piece of code does work as well.

Jim

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top