Merge two columns from two tables into one

后端 未结 3 1554
独厮守ぢ
独厮守ぢ 2021-01-15 21:57

I\'m trying to sort by two different columns from two different tables. This is the situtation:

I have 1 table \'shops\' with a column called \'shopy\', an INT colu

相关标签:
3条回答
  • 2021-01-15 22:07
     SELECT shopy as y FROM shops
     UNION ALL
     SELECT y FROM infra
     ORDER BY y ASC
    

    for Descending order write Order by y DESC.

    Demo at http://sqlfiddle.com/#!2/62884/1

    0 讨论(0)
  • 2021-01-15 22:16

    yes try this :if you want in descending order

    SELECT <columnnane> FROM tableName
    UNION ALL
    SELECT <columnnane> FROM tablename
    ORDER BY <columnnane> DESC
    

    :if you want in ascending order:

    SELECT <columnnane> FROM tableName
    UNION ALL
    SELECT <columnnane> FROM tablename
    ORDER BY <columnnane>
    
    0 讨论(0)
  • 2021-01-15 22:26

    yes of course is possible and yes of course you can.

    all you have to do is a temporary table with a column called whatever you want and insert the values of the 2 tables into the temporary table, in the same column.

    at the end you only need to select from the teporary table ordering it as you want.

    read the tutorial posted here

    0 讨论(0)
提交回复
热议问题