dennismonsewicz Posted December 3, 2007 Share Posted December 3, 2007 Ok.... I have written a PHP search App and I want it to search between like 8 or so tables in one Database. Here is my union mysql code: $query = "(select * from arcamax where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from drudge where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from google where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from human_events where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from newsmax where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from street where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from townhall where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from weatherbug where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from worldnet where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") order by mailedlist"; Now if I run a search with the above code it does not work...but if I limit the number of tables to two it works fine. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/80009-solved-mysql-union/ Share on other sites More sharing options...
Barand Posted December 3, 2007 Share Posted December 3, 2007 The "return" key is at the right of the main section of your keyboard. Quote Link to comment https://forums.phpfreaks.com/topic/80009-solved-mysql-union/#findComment-405377 Share on other sites More sharing options...
dennismonsewicz Posted December 3, 2007 Author Share Posted December 3, 2007 here ya go (with the added return key): $query = "(select * from arcamax where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from drudge where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from google where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from human_events where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from newsmax where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from street where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from townhall where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union ( select * from weatherbug where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") union (select * from worldnet where promo_code like \"%$trimmed%\" or start_end_date like \"%$trimmed%\" or mailedlist like \"%$trimmed%\" or description like \"%$trimmed%\" or orders like \"%$trimmed%\" or totalrevenue like \"%$trimmed%\") order by mailedlist"; Quote Link to comment https://forums.phpfreaks.com/topic/80009-solved-mysql-union/#findComment-405380 Share on other sites More sharing options...
Barand Posted December 3, 2007 Share Posted December 3, 2007 Do all those tables (arcamax, drudge,google etc) have exactly the same structure? Quote Link to comment https://forums.phpfreaks.com/topic/80009-solved-mysql-union/#findComment-405386 Share on other sites More sharing options...
dennismonsewicz Posted December 3, 2007 Author Share Posted December 3, 2007 well all of them do except one... Quote Link to comment https://forums.phpfreaks.com/topic/80009-solved-mysql-union/#findComment-405390 Share on other sites More sharing options...
dennismonsewicz Posted December 3, 2007 Author Share Posted December 3, 2007 the one that does not is the google one. I took it out and it works fine. How would I be able to search this DB table as well while still searching through all of the other DB tables? Quote Link to comment https://forums.phpfreaks.com/topic/80009-solved-mysql-union/#findComment-405392 Share on other sites More sharing options...
Barand Posted December 3, 2007 Share Posted December 3, 2007 You will have to dump the '*' and specify the columns selected so identically structured rows are returned from each union Quote Link to comment https://forums.phpfreaks.com/topic/80009-solved-mysql-union/#findComment-405393 Share on other sites More sharing options...
dennismonsewicz Posted December 3, 2007 Author Share Posted December 3, 2007 Problem Solved. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/80009-solved-mysql-union/#findComment-405400 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.