Combine two MYSQL table with same column Name

后端 未结 4 1193
猫巷女王i
猫巷女王i 2021-02-10 23:14

I have two table

table one is scheduletime

id    |   edition    | time   | 
1     |       1      | 9:23am |
2     |       2      | 10:23am|

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-10 23:35

    SELECT  Caption, Edition, Time
    FROM
            (
                SELECT  'Scheduled' Caption, Edition, time
                FROM    scheduleTime
                UNION   ALL
                SELECT  'Actual' Caption, Edition, time
                FROM    scheduleTime
            ) subquery
    ORDER   BY Edition, FIELD(Caption, 'Scheduled', 'Actual')
    
    • SQLFiddle Demo
    • SQLFiddle Demo (without using FIELD(), just plain ORDER BY...DESC)

    OUTPUT

    ╔═══════════╦═════════╦═════════╗
    ║  CAPTION  ║ EDITION ║  TIME   ║
    ╠═══════════╬═════════╬═════════╣
    ║ Scheduled ║       1 ║ 9:23am  ║
    ║ Actual    ║       1 ║ 9:23am  ║
    ║ Scheduled ║       2 ║ 10:23am ║
    ║ Actual    ║       2 ║ 10:23am ║
    ╚═══════════╩═════════╩═════════╝
    

提交回复
热议问题