coool Posted July 17, 2007 Share Posted July 17, 2007 Hi let's say I have two database tables FruitsTable Id..........name..........color 13..........a..................green 25..........k..................yellow 32..........o..................red VegetablesTable Id..........name..........color 13..........d..................green 25..........g..................white 32...........l..................red now can I do that ? <?php $fields="Id,name"; $tables="FruitsTable,VegetablesTabes"; $conditions="color in 'green,red'"; $sql="SELECT $fields FROM $tables WHERE $conditions"; ?> error: Id is ambiguous !! ??? Quote Link to comment https://forums.phpfreaks.com/topic/60401-solved-merging-two-tables-in-mysql-query/ Share on other sites More sharing options...
pikemsu28 Posted July 17, 2007 Share Posted July 17, 2007 $query = "SELECT $fields FROM FruitsTable WHERE $conditions UNION SELECT $fields FROM VegetablesTable WHERE $conditions"; Quote Link to comment https://forums.phpfreaks.com/topic/60401-solved-merging-two-tables-in-mysql-query/#findComment-300485 Share on other sites More sharing options...
coool Posted July 17, 2007 Author Share Posted July 17, 2007 This is great Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/60401-solved-merging-two-tables-in-mysql-query/#findComment-300609 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.