SQL Joins

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
h123z
Forum Newbie
Posts: 7
Joined: Tue Sep 18, 2007 5:18 am

SQL Joins

Post 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
User avatar
Peter Anselmo
Forum Commoner
Posts: 58
Joined: Wed Feb 27, 2008 7:22 pm

Re: SQL Joins

Post by Peter Anselmo »

Can you describe how the user table relates to the seller table? The database design isn't clear from your description.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: SQL Joins

Post 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
 
Post Reply