How can I merge the columns from two tables into one output?

前端 未结 5 940
我寻月下人不归
我寻月下人不归 2020-12-07 12:07

I have two tables with similar information. Let\'s call them items_a and items_b. They should be one, but they are coming from different sources, s

5条回答
  •  情歌与酒
    2020-12-07 12:50

    I guess that what you want to do is an UNION of both tables.

    If both tables have the same columns then you can just do

    SELECT category_id, col1, col2, col3
      FROM items_a
    UNION 
    SELECT category_id, col1, col2, col3 
      FROM items_b
    

    Else, you might have to do something like

    SELECT category_id, col1, col2, col3
      FROM items_a 
    UNION 
    SELECT category_id, col_1 as col1, col_2 as col2, col_3 as col3
      FROM items_b
    

提交回复
热议问题