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>"; } ?> Quote Link to comment 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) Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
fenway Posted November 18, 2011 Share Posted November 18, 2011 There's nothing unique about that. Quote Link to comment 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; Quote Link to comment 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). Quote Link to comment 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. Quote Link to comment 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.