matfish Posted March 9, 2009 Share Posted March 9, 2009 Hi there, I have split my customers table into customers_2008 and customers_2009. How would I do a mysql search on both tables (I'm using php to output the results)? I've looked into Joins but customers_2008.customerID = customers_2009.customerID is not going to work. I think a join is for foreign keys? Correct me if I'm using it wrong. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/ Share on other sites More sharing options...
Mchl Posted March 9, 2009 Share Posted March 9, 2009 Why did you split those tables in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780237 Share on other sites More sharing options...
matfish Posted March 9, 2009 Author Share Posted March 9, 2009 The customers table was 290Mb, so was trying to archeive it into "years". I've been having alot of trouble with the table lately and I have to keep optimising/repairing it. If I could do the SQL to merge/join both tables then it would be easier. If not, then I will continue to use the whole table altogether again. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780245 Share on other sites More sharing options...
matfish Posted March 9, 2009 Author Share Posted March 9, 2009 Splitting the table now is causing a few more problems than expected and I'm going to put it all together again I think. I'll have to bigdump it! Out of curiosity, would it have been possible to have done what I was trying to do? Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780252 Share on other sites More sharing options...
fenway Posted March 9, 2009 Share Posted March 9, 2009 UNIONs. Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780258 Share on other sites More sharing options...
kickstart Posted March 9, 2009 Share Posted March 9, 2009 Hi Yep, very easy. Select *, "2008" as CustomerYear from customers_2008 where ordercompleteddate is null UNION Select *, "2009" as CustomerYear from customers_2009 where ordercompleteddate is null All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780262 Share on other sites More sharing options...
Mchl Posted March 9, 2009 Share Posted March 9, 2009 What MySQL version are you using? Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780291 Share on other sites More sharing options...
matfish Posted March 9, 2009 Author Share Posted March 9, 2009 Thanks Keith, I will give that a bash and see if it works. I'm using php and mysql 5 Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780358 Share on other sites More sharing options...
matfish Posted March 9, 2009 Author Share Posted March 9, 2009 Haven't found any issues in using "UNION" as of yet. Many thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780364 Share on other sites More sharing options...
Mchl Posted March 9, 2009 Share Posted March 9, 2009 You might want to do partitioning of these tables instead of splitting them in two. Quote Link to comment https://forums.phpfreaks.com/topic/148584-mysql-join-maybe/#findComment-780449 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.