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

Query a table for values in a second table of values

Status
Not open for further replies.

scootswiss

Technical User
Mar 1, 2001
11
US
I have a database with 2 tables and doing a study of certain products shipped. Table1 records are a line detail of SKU's shipped. For example if 1 item shipped then only column1 has data, but if 2 items shipped there is data in couumns 1 and 2. The data is the shipped SKU. Table2 is a SKU listing of specific product types. Table1 has 150M records and table 2 has 280 records. How can I query against Table1 using Table2 to flag or pull out those orders that included any of the products in table 2? Can the In operator be used in my query design referencing Table2? Other method?

Thanks in advance for your help

scootswiss
 
The in operator can be used only if you can uniquely identify a product type with one field. For example:
[tt]
SELECT *
FROM Table1
WHERE ProductType=(
SELECT ProductType
FROM Table2
)
[/tt]
However, if you have more than one field, you'll have to do a left join and filter out no match records using a null condition. For example:
[tt]
SELECT Table1.*
FROM Table1 LEFT JOIN Table2
ON Table1.ProductType=Table2.ProductType And
Table1.ProductCategory=Table2.ProductCategory
WHERE Table2.ProductType Is Null And Table2.ProductCategory Is Null
[/tt]
 
It does not appear that this will work because we are not searching for null record fields, but searching for numbers in all fields of a record that are in a list of numbers in a another table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top