corillo181 Posted May 19, 2008 Share Posted May 19, 2008 hey i want to select 3 tables, in one table i have some info about the user such as a username, the next table i have personal information about that user such as name ect. that last table i have photos of that user.. i did a query as this SELECT w.usename, i.name, p.path FROM user w, user_info i, photos p, WHERE w.id = i.id AND w.id = p.id this works fine, but if the user has more then one picture the user info show twice. i try using DISTINCT but it didn't work. any help? thanks in advance. Link to comment https://forums.phpfreaks.com/topic/106278-help-joining-table/ Share on other sites More sharing options...
beboo002 Posted May 19, 2008 Share Posted May 19, 2008 I think you join the first two table user and user_info and get id then use photo table with DISTINCT pass id in where like $sql="SELECT w.id as id,w.usename, i.name, p.path FROM user w, user_info i, WHERE w.id = i.id "; $query=mysql_query($sql,$link); while($row=mysql_fetch_array($query)){ $id=$row[id]; $sql2="select DISTINCT id, path from photos where id=$id"; echo the result } may this idea help you Link to comment https://forums.phpfreaks.com/topic/106278-help-joining-table/#findComment-544676 Share on other sites More sharing options...
corillo181 Posted May 19, 2008 Author Share Posted May 19, 2008 yeah i know is easy to do it like this, i was just trying to see if there was a way of doing it like i wanted. Link to comment https://forums.phpfreaks.com/topic/106278-help-joining-table/#findComment-545125 Share on other sites More sharing options...
revraz Posted May 19, 2008 Share Posted May 19, 2008 Use LIMIT 1 and just pull one row? Link to comment https://forums.phpfreaks.com/topic/106278-help-joining-table/#findComment-545147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.