Page 1 of 1

SQL Joins

Posted: Thu Feb 28, 2008 4:25 am
by h123z
Hi,
how do i join 2 tables based on a third "index" table
for example, i have one table with buyer name and buyer id, one table with seller name and seller id, and a third table with user id and buyer id
how do i get a list of buyer name and seller name, using table 3?

thanks

Re: SQL Joins

Posted: Thu Feb 28, 2008 7:26 pm
by Peter Anselmo
Can you describe how the user table relates to the seller table? The database design isn't clear from your description.

Re: SQL Joins

Posted: Thu Feb 28, 2008 10:15 pm
by Benjamin
I believe you want something like this:

Code: Select all

 
SELECT
  b.name AS buyer_name,
  s.name AS seller_name
FROM
  buyer b,
  seller c,
  buy2sell bs
WHERE
  b.id = bs.id
  AND bs.id = c.id