matty Posted March 30, 2007 Share Posted March 30, 2007 Hi, I have two tables in my database. One is called 'hotfood', the other is 'coldfood'. What I want to do is have a single SELECT query for both of these tables. This is so I can then use 'mysql_num_rows' on this query, like so. if(mysql_num_rows($id)==0) { print "Food type does not exsist"; } else { -- } It basicaly to do a search type thing, the above checks that the food name exists by checking both the hot and cold food table, therefore I need to two merged into the select query so that I can search it. Get me? Sorry for the poor explanation. Thanks in advance, Matt Link to comment https://forums.phpfreaks.com/topic/44960-solved-db-help-merging-2-tables-with-a-select-query/ Share on other sites More sharing options...
Psycho Posted March 30, 2007 Share Posted March 30, 2007 You could create a merge table: http://www.jeff-barr.com/?p=110 where the two tables would exist as a virtual combined table. But, I would suggest creating just one table and adding a column to identify wether the food is hot, cold, or both - instead of having two tables. Link to comment https://forums.phpfreaks.com/topic/44960-solved-db-help-merging-2-tables-with-a-select-query/#findComment-218285 Share on other sites More sharing options...
Barand Posted March 30, 2007 Share Posted March 30, 2007 SELECT name, 'hot' AS foodtype FROM hotfood WHERE name LIKE '%$search%' UNION SELECT name, 'cold' AS foodtype FROM coldfood WHERE name LIKE '%$search%' Link to comment https://forums.phpfreaks.com/topic/44960-solved-db-help-merging-2-tables-with-a-select-query/#findComment-218317 Share on other sites More sharing options...
matty Posted March 30, 2007 Author Share Posted March 30, 2007 Thanks Barand, that worked perfect Link to comment https://forums.phpfreaks.com/topic/44960-solved-db-help-merging-2-tables-with-a-select-query/#findComment-218412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.