douchongzhang9267 2017-06-06 12:02
浏览 11

根据时间显示多个表并显示源表

So, for example, I have 3 tables

Table 1: name

id | name | time
 1 | Bob  | 20.42

Table 2: item

id | item   | time
 1 | Bottle | 18.42
 2 | Box    | 21.42

Table 3: food

id | Food | time
1 | Steak | 19.42

So I want to display them like this

From table item: 1 | Bottle
From table food: 1 | Steak
From table name: 1 | Bob
From table item: 2 | Box
  • 写回答

2条回答 默认 最新

  • dtv11049 2017-06-06 12:05
    关注

    Use UNION ALL:

    select id, name
    from (
        select * from name
        union all
        select * from item
        union all
        select * from food ) t
    order by t.`time`
    
    评论

报告相同问题?