Need Join Help

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
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Need Join Help

Post by thinsoldier »

Hi, could someone help me with a join query.

I've included a simplified diagram of my database and my query so far which doesn't work
Image

Code: Select all

SELECT house.id, house.propertyname
FROM
  residences AS house,
  residents_to_residences AS r2r,
  residents AS person
WHERE residence_id != house.id
GROUP BY house.id
  ORDER BY house.propertyname
Warning: I have no idea what I'm talking about.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Need Join Help

Post by VladSun »

You need to LEFT join these tables and filter the records with resident_to_residences data is NULL
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply