Combine two MYSQL table with same column Name

后端 未结 4 1190
猫巷女王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:19

    Try this:

    SELECT 
        'Scheduleed' AS Caption, 
        Edition, 
        time 
    FROM scheduletime
    UNION ALL
    SELECT 
        'actual' AS Caption, 
        Edition, 
        time 
    FROM actualtime
    ORDER BY Edition, Caption DESC
    

    OUTPUT:

    |    CAPTION | EDITION |    TIME |
    ----------------------------------
    | Scheduleed |       1 |  9:23am |
    |     actual |       1 | 10:23am |
    | Scheduleed |       2 | 10:23am |
    |     actual |       2 | 11:23am |
    

    See this SQLFiddle

    0 讨论(0)
  • 2021-02-10 23:22

    You can use :-

    select * from(
    select 'Scheduleed' as Caption ,edition,time from scheduletime
    
    union all
    
    select 'actual' as Caption,edition,time from actualtime
    )x 
    
    0 讨论(0)
  • 2021-02-10 23:25
    select * from
    (select 'Scheduleed' as Caption, Edition as Edition, Time as Time from scheduletime
    
    union all
    
    select 'actual' as Caption, Edition as Edition, Time as Time from actualtime) as a
    
    order by Edition
    

    Maybe this will help you

    0 讨论(0)
  • 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 ║
    ╚═══════════╩═════════╩═════════╝
    
    0 讨论(0)
提交回复
热议问题