php - Select records from 2 tables and ordering them -



php - Select records from 2 tables and ordering them -

i have 2 tables , b next records

--table a-- id date value 1 09/01/2012 reward 2 09/01/2012 purchase 3 07/01/2012 reward 4 07/01/2012 purchase --table b-- id id_from_a date value 1 1 10/01/2012 generated rewrd 2 3 08/01/2012 generated reward

now want result below

id date value 1 10/01/2012 generated reward 1 09/01/2012 reward 2 09/01/2012 purchase 3 08/01/2012 generated reward 3 07/01/2012 reward 4 07/01/2012 purchase

i know using unions merge these 2 tables how order have mentioned above ?

a union can have single order clause specified @ end applies entire, combined result set.

select id, date, value table_a union select id, date, value table_b order id, date desc

if don't need deduplicating feature of union operation, union yield improve performance.

select id, date, value table_a union select id, date, value table_b order id, date desc

php mysql

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -