Hi.
I have three tables, each contain some common information, and some information that is unique to the table.
For example: uid
, date
are universal among the tables, but one table can contain a column type
while the other contains currency
.
I need to query the database and get the last 20 entries (date DESC
) that have been entered in all three tables.
My options are:
Query the database once, with one large query, containing three
UNION ALL
clauses, and pass along fake values for columns, IE:FROM ( SELECT uid, date, currency, 0, 0, 0
and later on
FROM ( SELECT uid, date, 0, type, 0, 0
This would leave me with allot of null-valued fields..
OR I can query the database three times, and somehow within PHP
sort
through the information to get the combined latest 20 posts. This would leave me with an excess of information - 60 posts to look through (LIMIT 20
) * 3 - and force me to preform some type of addtional quicksort every time.
What option is better/any alternate ideas?
Thanks.