简体   繁体   English

从具有不同顺序列的两个表中选择

[英]Select from two tables with different order column

I have two tables with three columns each:我有两个表,每个表三列:

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

For sitemap.xml I want add all item from the two tables in file order by time.对于sitemap.xml我想按时间按文件顺序添加两个表中的所有项目。 The two tables are separate and time field are reg_time and time_log .这两个表是分开的,时间字段是reg_timetime_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在以下情况下,结果集包括tbl_musictbl_movie表的内容

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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