Subject: SQL Join tables help
Posted By: tdaustin Post Date: 1/10/2006 11:07:52 PM
Hi All,

Im trying to write a SQL statement that will join 2 tables based on a customer has 2 specific products.
eg.

Table 1:  Customer

MemberID
MemberName
Email ect

Table 2:  Products

ProductID
MID (MemberID of table 1)
ProductName

So how do i write a sql statement to only bring up say cutomers that have a ProductName of "Computers" AND "Laptops"  They must have both Computers as an entry in the products table and an entry of Laptops in the relational database.

Your help would be much appreciated.

Tim :)


TDA
Reply By: ChrisScott Reply Date: 1/11/2006 4:34:53 AM
Hi Tim,

One way would be to use subqueries...

SELECT MemberID, MemberName FROM Customer
WHERE MemberID IN(SELECT MID FROM Products WHERE ProductName = 'Computers')
AND MemberID IN(SELECT MID FROM Products WHERE ProductName = 'Laptops');

HTH,

Chris


Reply By: tdaustin Reply Date: 1/11/2006 3:57:03 PM
Fantastic!

Thanks chris.  exactly what i needed.

Thank you

Tim :)

TDA

Go to topic 38191

Return to index page 674
Return to index page 673
Return to index page 672
Return to index page 671
Return to index page 670
Return to index page 669
Return to index page 668
Return to index page 667
Return to index page 666
Return to index page 665