Page 1 of 1

Merge Two Tables Data

Posted: Sat Apr 07, 2012 9:25 am
by Dale
Hey,

I've Google'd about and tried many different examples of what I need and none seemed to work, soooo hopefully you'll be able to help me. Basically I have a table that "logs" user activity and also a table that is for "wall posts" and I basically want to show both of them together in one list.

Here's the table's structure...
log
id, userid, loginfo, timeadded

wallpost
id, userid, thepost, timeadded

Now I want to have it merge both together and ordered using the timeadded value. Now I've tried doing it with JOIN, LEFT JOIN and various other methods (including having two seperate queries and results that are added together as a seperate array - but that didn't work either).

Any ideas?

Re: Merge Two Tables Data

Posted: Sat Apr 07, 2012 8:20 pm
by McInfo
Try UNION.

Re: Merge Two Tables Data

Posted: Sun Apr 08, 2012 5:01 pm
by califdon
As McInfo said, if you want to collect ALL records of BOTH tables, sorted by whatever, UNION is the kind of query you need to use. But if you are trying to MATCH UP records with the same userid, or something, and display both loginfo and thepost, then you have an entirely different situation. In that case, you have to decide what to do for each possible situation, such as loginfo, but no thepost data, or the reverse, and whether you want to group by userid or just sort by timestamp.