Removing duplicate results while using UNION SELECT

前端 未结 2 1481
梦谈多话
梦谈多话 2021-01-12 03:57

Ive got a problem with a MySQL query.

Let\'s say, we have two tables:

id qty

1......1

2......1

3......1

4......3

2条回答
  •  别那么骄傲
    2021-01-12 04:43

    GROUP BY didnt help either

    Really? Did you try like this?

    SELECT id, MAX(qty) AS qty
    FROM
    (
        SELECT id, qty FROM table1
        UNION ALL
        SELECT id, qty FROM table2
    ) T1
    GROUP BY id
    

提交回复
热议问题