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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Issue??

Status
Not open for further replies.

zishan876

Programmer
Mar 19, 2007
61
US
Hi I have the following:
Code:
SELECT account, name, paidAmount,Id,lob,creditStatus   FROM adsBostonGlobeAdvert a WHERE NOT EXISTS  (SELECT * FROM Master m WHERE a.account = m.account      AND desk NOT IN ('PUR', 'WJMPURGE')      AND current0 <> 0)

I am trying to say give me accounts that are in A and not Exist in M
...
For some reason I am getting accounts that exist in both files...
Can someone please tell me where I went wrong...
Thanks
 
Don't use not exists use a left join instead.
Code:
SELECT account, name, paidAmount,Id,lob,creditStatus   
FROM adsBostonGlobeAdvert a 
left join Master m on a.account = m.account     
and desk NOT IN ('PUR', 'WJMPURGE')      AND current0 <> 0
where m.account is null

This assumes that the fields desk and current0 are in Master. (BTW, master is a really poor name for a table as it is the name of a system database, you really should avoid doing things like that for clarity.)

"NOTHING is more important in a database than integrity." ESquared
 
Try using a Left Join:
Code:
SELECT account, name, paidAmount,Id,lob,creditStatus
FROM adsBostonGlobeAdvert a
   LEFT Join Master m ON a.account = m.account
Where m.account IS NULL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top