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

How to display record set where value does not exist 1

Status
Not open for further replies.

dadazs

Technical User
Oct 29, 2010
37
GB
hello,
I am new at sql & appologies if it is a too basic question; however, i am still working on it:

select * from CONTACT1
inner join CONTSUPP
on CONTACT1.ACCOUNTNO= CONTSUPP.ACCOUNTNO

where CONTACT1.KEY1='Client' and

(CONTSUPP.RECTYPE = "P" )=False



I want to display records where CONTSUPP.RECTYPE = "P" does not exist.

I cannot use CONTSUPP.RECTYPE <> "P" because it displays other rectype values.
I am interested in records that do not have "p" value only & all other rectype letter should be ignored.

Many Thanks
 
You can't do an inner (equi) join to a row that does not exist, so you need to use NOT EXISTS:
Code:
SELECT
  *
FROM Contact1 c1
WHERE Key1 = 'Client'
AND NOT EXISTS (
  SELECT 1
  FROM ContSupp
  WHERE AccountNo = c1.AccountNo
    AND RecType = 'P'
)
You could use a LEFT (outer) join and test for a null value in a not-null column of ContSupp, but NOT EXISTS probably gives a clearer idea of what you are looking for.

HTH
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top