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!

Hello, I have a query that I wa

Status
Not open for further replies.

bennynye

Programmer
Feb 8, 2002
10
0
0
US
Hello,

I have a query that I want to return a list of contacts that do not have any rows with a 't' in the Licenced column in a one-many table. I have checked that this case does occur, but my SQL returns 0 contacts. If anyone could point me in the right direction I would appreciate it.

Code:
SELECT     COUNT(Distinct sysdba.CONTACT.CONTACTID) AS Expr1
FROM         sysdba.CONTACT LEFT OUTER JOIN
                      sysdba.C_LICENSE ON sysdba.CONTACT.CONTACTID = sysdba.C_LICENSE.CONTACTID
WHERE     (sysdba.C_LICENSE.CONTACTID NOT IN
                          (SELECT     sysdba.C_License.contactid
                            FROM          sysdba.C_License
                            WHERE      sysdba.C_LICENSE.LICENSED = 'T'))




Thanks,

 
SELECT COUNT(Distinct sysdba.CONTACT.CONTACTID) AS Expr1
FROM sysdba.CONTACT
WHERE NOT EXISTS
(SELECT sysdba.C_License.contactid
FROM sysdba.C_License
WHERE sysdba.C_LICENSE.CONTACTID = sysdba.CONTACT.CONTACTID
AND sysdba.C_LICENSE.LICENSED = 'T')


"Helping others to help themselves..."
=================================
Thomas V. Flaherty Jr.
Birch Hill Technology Group, Inc.
 
Great solution ThomVF,

I used your method of going to the Parent table without a join and it worked great. I changed it slightly to incorporate a function that I am more familiar with, the NOT IN, but that was pretty much the only change.

Thanks again,
bennynye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top