aunquarra Posted February 2, 2007 Share Posted February 2, 2007 Okay, I have two tables I frequently join. One is a list of people, and the other is a list of details about those people. I typically do the joins with the id number in the people table and a column with people IDs in the details table. So it would be like... SELECT `people`.*, `details`.* from `people` left join `details` on `people`.`id`=`details`.`people_id`.... The trick is, as you might guess by the way I'm building it, each people_id could have multiple rows in the details table. Typically, I only call on the details table when I'm looking at one specific person, so no biggie there. But in this case, I need to retrieve a list of people. What I'm wanting to accomplish is to, without resource-heavy sub-selects, return only people who don't have a specific detail. So like, if I'm looking for people who are unemployed, and the way I tell if a person is employed is to check and see if they have a row in the details table that has a `detail_category`='job', then to return a list of unemployed people, I have to check to see if they don't have such row. The more I think about it, the more I think this isn't going to be something I can do with a simple join. Either I'm going to have to have PHP do the legwork or do a subselect. But I figured I'd ask the professionals... Quote Link to comment https://forums.phpfreaks.com/topic/36771-solved-joins-and-conditional-logic/ Share on other sites More sharing options...
fenway Posted February 2, 2007 Share Posted February 2, 2007 Why not just add this condition to your ON clause and add an IS NULL on the details table in your WHERE clause? Quote Link to comment https://forums.phpfreaks.com/topic/36771-solved-joins-and-conditional-logic/#findComment-175453 Share on other sites More sharing options...
aunquarra Posted February 2, 2007 Author Share Posted February 2, 2007 Perfect! Not sure why I didn't think of that, but thank you! Quote Link to comment https://forums.phpfreaks.com/topic/36771-solved-joins-and-conditional-logic/#findComment-175482 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.