简体   繁体   中英

Select from two tables with different order column

I have two tables with three columns each:

  • tbl_music (id, title, reg_time)
  • tbl_movie (id, title, time_log)

For sitemap.xml I want add all item from the two tables in file order by time. The two tables are separate and time field are reg_time and time_log .

How can I join two tables and order from value on two tables?

In the following case, the result set includes the contents of both the tbl_music and tbl_movie tables

select * from 
( select id, title, reg_time as time from tbl_music 
  union all
  select id, title, time_log as time from tbl_movie
) results
order by time

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM