shcKr- Posted September 4, 2008 Share Posted September 4, 2008 Hey, im just struggling with this: I want to be able to search multiple tables in my mysql database, i have bedroom, dining, living ect. and i want to be able to search them and show the results, i tried: $query = "SELECT dining.title FROM bedroom UNION SELECT bedroom.title FROM dining WHERE bedroom.title LIKE '%".$keywords[$i]."%' OR dining.title = '%".$keywords[$i]."%'"; but that doesn't work, I'm not that experienced in sql and the code I just gave you will probably be laughed at But atleast i tried - but i really do need help on this. Link to comment https://forums.phpfreaks.com/topic/122699-solved-union-maybe-joining-tables/ Share on other sites More sharing options...
fenway Posted September 4, 2008 Share Posted September 4, 2008 That's because after the union the fields "lose" their prefix... why not: ( SELECT title FROM bedroom WHERE title LIKE '%".$keywords[$i]."%' ) UNION ALL ( SELECT title FROM dining WHERE title = '%".$keywords[$i]."%'"; ) Link to comment https://forums.phpfreaks.com/topic/122699-solved-union-maybe-joining-tables/#findComment-633661 Share on other sites More sharing options...
shcKr- Posted September 4, 2008 Author Share Posted September 4, 2008 thanks, that did it perfectly You have no idea how long i been trying to get that to work Link to comment https://forums.phpfreaks.com/topic/122699-solved-union-maybe-joining-tables/#findComment-633691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.