Mr Chris Posted April 4, 2011 Share Posted April 4, 2011 Hello, Hopefully an easy one. Say I want to search two tables for the same thing, where each of the tables has the column 'name' in it: How would I correctly do it, I tried: SELECT * FROM table1, table2 WHERE table1.name = 'John' OR table2.name = 'John' But this brings back results for table1 and table2 in a single row, even though the result returned should just be from table2 as that's the only occurrance of John? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/232660-simple-query-on-two-tables/ Share on other sites More sharing options...
kickstart Posted April 4, 2011 Share Posted April 4, 2011 Hi Use a UNION (or a UNION ALL) SELECT * FROM table1 WHERE table1.name = 'John' UNION SELECT * FROM table2 WHERE table2.name = 'John' All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/232660-simple-query-on-two-tables/#findComment-1196690 Share on other sites More sharing options...
Mr Chris Posted April 4, 2011 Author Share Posted April 4, 2011 Thank you for your help Quote Link to comment https://forums.phpfreaks.com/topic/232660-simple-query-on-two-tables/#findComment-1196722 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.