mySQL Query JOIN in same table

Posted by jeerose on Stack Overflow See other posts from Stack Overflow or by jeerose
Published on 2010-04-07T03:34:17Z Indexed on 2010/04/07 3:43 UTC
Read the original article Hit count: 295

Filed under:
|
|

Table structure goes something like this:

Table: Purchasers Columns: id | organization | city | state

Table: Events Columns: id | purchaser_id

My query:

SELECT purchasers.*, events.id AS event_id 
FROM purchasers 
INNER JOIN events ON events.purchaser_id = purchasers.id 
WHERE purchasers.id = '$id'

What I would like to do, is obviously to select entries by their id from the purchasers table and join from events. That's the easy part. I can also easily to another query to get other purchasers with the same organization, city and state (there are multiples) but I'd like to do it all in the same query. Is there a way I can do this?

In short, grab purchasers by their ID but then also select other purchasers that have the same organization, city and state.

Thanks.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about query