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!

SELECT data that is not in a table from another table? 1

Status
Not open for further replies.

Niavlys

IS-IT--Management
Jun 3, 2002
197
CA
Hi,
I have to tables : Models_Default and Soft_Info

Models_Default has 2 fields : TemplateID and SoftID
Soft_Info has 3 fields : SoftID, SoftName, Version

I need to get data in from Soft_Info table that SoftID IS NOT in Models_Default table and TemplateID is equal to 15.

I tried LEFT, RIGHT and INNER JOIN combinations but I can't figure out how to retrieve what I need.


I have something like that but it doesn't work
Code:
SELECT Soft_Info.Software, Soft_Info.Version, Soft_Info.SoftID
FROM Soft_Info LEFT JOIN Models_Default ON Soft_Info.SoftID = Models_Default.SoftID 
WHERE Models_Default.SoftID Is Null AND Models_Default.TemplateID=15

Can someone help me please? It is hard to explain so if you need more info...

Thanks!
 
Since the template ID is only in the default table, it is not possible to have a value fo 15 if the record does not exist.

Questions about posting. See faq183-874
 
Try this:

Code:
SELECT
   Soft_Info.Software,
   Soft_Info.Version,
   Soft_Info.SoftID
FROM
   Soft_Info
   LEFT JOIN Models_Default
      ON Soft_Info.SoftID = Models_Default.SoftID
      AND Models_Default.TemplateID=15
WHERE Models_Default.SoftID Is Null

-------------------------------------
It is better to have honor than a good reputation.
(Reputation is what other people think about you. Honor is what you know about yourself.)
 
Putting conditions in the JOIN clause is very useful, sometimes.

-------------------------------------
It is better to have honor than a good reputation.
(Reputation is what other people think about you. Honor is what you know about yourself.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top