jaymc Posted December 11, 2007 Share Posted December 11, 2007 I am familiar with using JOIN to join fields onto a row However, I want something a little different, not sure if it can be done I have 2 tables, one has image comments and another has profile comments In 1 query, I want to pull in the last 10 profile comments and last 10 image comments. Virtually, I would have 20 rows in a temp table, I would then like to order them and display the last 10 posted Of course I can do the last bit, its just getting the 20 rows together in 1 query. Can it be done? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 11, 2007 Share Posted December 11, 2007 You can use UNION http://dev.mysql.com/doc/refman/5.0/en/union.html Quote Link to comment Share on other sites More sharing options...
jaymc Posted December 11, 2007 Author Share Posted December 11, 2007 Cheers, I will give that a try tonight! Quote Link to comment Share on other sites More sharing options...
jaymc Posted December 16, 2007 Author Share Posted December 16, 2007 Ok I had a go at this and Its not doing what I want, just need to know if its the rules of UNION I have 2 tables 1 holds profile comments 1 holds image comments Both tables have similar fields, howeverm, the image one has a field for the image ID, and the profile one does not, but that has a field for the IP address I need to pull out the image ID from the image comments table, but it does not exist in the profile table. Is this impossible to do? It would be good to have the result fill the image ID field as NULL if it doesnt exist, that way if its NULL I know it must be a profile comment, if its not, it must be an IMAGE comment, which is precicesly what I want Any ideas? Quote Link to comment Share on other sites More sharing options...
fenway Posted December 18, 2007 Share Posted December 18, 2007 Just don't union *... specify the fields you want, as long as the datatypes match up, you're ok. Quote Link to comment 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.