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!

Query Table compare for field values NOT Existing in a specific table 1

Status
Not open for further replies.

ljsmith91

Programmer
May 28, 2003
305
US
I have a database with 3 different tables. Each has a field(model) that is used for the exact same purpose. In simple terms, I want to eliminate the field in 2 of the tables so that the field is contained in only 1 table instead of 3. In order to do this, I want to know how many distinct records of this field exist in each table. If Table1 is the table that I want to keep the field, how do I create a query that will list the similar field in both Table2 and Table3 only if it doesn't already have a record in Table1? Is there a way to query and get a compare of field values from Table2 and Table3 that DO NOT exist in Table1? I know it's some sort of OUTER Join logic but I can't seem to find a query that simplifies this. This one sample that just doesn't do the trick for me.

SELECT t1_model,t2_model,t3_model
from T1
Outer Join T2
on t1_model <> t2_model
Outer join t3
on t1_model <> t3_model

Thanks for any quidance. -ls
 
Select model
from(Select model
from t2
union
Select model
from t3
)T1And2
left join ti
on t1.model=T1And2.model
where t1.model is null

will give models that are in t2 and t3 that are not in t1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top