Lukeidiot Posted November 16, 2011 Share Posted November 16, 2011 Okay, Here's my tables: Table: husbands ------------------- Column: sid #################### Table: wives ------------------- Column: sid #################### Table: children ------------------- Column: sid I am trying to select the sid of all with say "4003". I need to select the unique sid for all tables combined, then display it in php. Wheres what I was thinking, but doesnt work: <?php $sql = mysql_query(" SELECT sid FROM husbands, wives WHERE husbands.sid = wives.sid "); while ($row = mysql_fetch_assoc($sql)){ echo "".$row['husbands.sid']." <br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/251271-how-to-select-unique-from-multiple-tables/ Share on other sites More sharing options...
Muddy_Funster Posted November 17, 2011 Share Posted November 17, 2011 Try: SELECT sid FROM husbands INNER JOIN wives ON (husbands.sid = wives.sid) INNER JOIN children ON (husbands.sid = wives.sid) Link to comment https://forums.phpfreaks.com/topic/251271-how-to-select-unique-from-multiple-tables/#findComment-1288990 Share on other sites More sharing options...
The Little Guy Posted November 17, 2011 Share Posted November 17, 2011 I got this to work for me: select * from husbands join wives using(sid) join children using(sid) where husbands.sid = 4003; output with 2 children (see attachment) [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/251271-how-to-select-unique-from-multiple-tables/#findComment-1289122 Share on other sites More sharing options...
fenway Posted November 18, 2011 Share Posted November 18, 2011 There's nothing unique about that. Link to comment https://forums.phpfreaks.com/topic/251271-how-to-select-unique-from-multiple-tables/#findComment-1289179 Share on other sites More sharing options...
The Little Guy Posted November 18, 2011 Share Posted November 18, 2011 select * from husbands join wives using(sid) join children using(sid) where husbands.sid = 4003 group by husbands.sid; Link to comment https://forums.phpfreaks.com/topic/251271-how-to-select-unique-from-multiple-tables/#findComment-1289183 Share on other sites More sharing options...
Lukeidiot Posted November 18, 2011 Author Share Posted November 18, 2011 select * from husbands join wives using(sid) join children using(sid) where husbands.sid = 4003 group by husbands.sid; Nice job man! If you guys are curious I am coding a Family Tree project for a relative (free work). Link to comment https://forums.phpfreaks.com/topic/251271-how-to-select-unique-from-multiple-tables/#findComment-1289231 Share on other sites More sharing options...
fenway Posted November 18, 2011 Share Posted November 18, 2011 Again, * is garbage with GROUP BY -- don't do that. Link to comment https://forums.phpfreaks.com/topic/251271-how-to-select-unique-from-multiple-tables/#findComment-1289384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.