Hi

Ive reached my own limit with this one... hopefully its not that tricky.

I have a products table, each with a unique id. I then have a complimentary_items table which links two products as 'matches'.

The complimentary items table has three columns: id, prod_id1, prod_id2. Can I write 1 query, which pulls out all of the matches as well as fetches the associated names from the product table?

lworks

Something like this should work:

SELECT a.id, a.prod_id1, b.description as desc1, a.prod_id2, c.description as desc2
FROM comp_items a
INNER JOIN products b ON a.prod_id1 = b.prod_id
INNER JOIN products c ON a.prod_id2 = c.prod_id
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.