mattm1712 Posted March 31, 2012 Share Posted March 31, 2012 hi im trying to echo out all the possibilities from one column in 2 different tables, both with the same structure. if that makes sense this is what i have $query = mysql_query("SELECT * FROM stanjamesprem,centrebetprem GROUP BY eventname ORDER BY eventtime "); while($row = mysql_fetch_assoc($query)) { echo $row[eventname]; } if i take one of the tables out it works fine but if i have 2 table names it doenst work please help me cheers matt any questions please ask away Quote Link to comment https://forums.phpfreaks.com/topic/260084-select-from-multiple-tables/ Share on other sites More sharing options...
Nasir Posted March 31, 2012 Share Posted March 31, 2012 You can use a JOIN syntax and GROUP to accomplish what you want. Check Here Quote Link to comment https://forums.phpfreaks.com/topic/260084-select-from-multiple-tables/#findComment-1333051 Share on other sites More sharing options...
sunfighter Posted March 31, 2012 Share Posted March 31, 2012 When you have a SELECT and a FROM you need to have a WHERE or you're just going to get everything in the world. The WHERE is the device that tells you the row or rows that you want to look at. The GROUP BY is not needed. After you get your query working you might need a ORDER BY but wait on that. EDIT PS: You really shouldn't use the * but should name the columns you want to see. When you do that you need to have the table name plus a dot plus the column from that table. like SELECT stanjamesprem.column, centrebetprem.whatelse FROM stanjamesprem, centrebetprem WHERE stanjamesprem.ID = centrebetprem.anotherID; It's hard to give advise when i don't know what your trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/260084-select-from-multiple-tables/#findComment-1333097 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.