我知道使用 UNION 会删除 sql 中的重复行,但我想知道如何删除与另一行共享重复主键的重复行。这是我的查询
"
SELECT
isbn, title, rank,
lowest_new_price AS lowest_price,
lowest_new_location AS lowest_location,
FROM ".TBL_BOOKS."
UNION
SELECT
isbn, title, rank,
lowest_used_price AS lowest_price,
lowest_used_location AS lowest_location,
FROM ".TBL_BOOKS."
ORDER BY rank ASC"
输入数据
isbn, title, rank, lowest_new_price, lowest_new_location
00001 t1 1 100 uk
00001 t1 1 200 uk
00002 t3 5 50 uk
所需的输出数据
isbn, title, rank, lowest_new_price, lowest_new_location
00001 t1 1 100 uk
00002 t3 5 50 uk
或者
isbn, title, rank, lowest_new_price, lowest_new_location
00001 t1 1 200 uk
00002 t3 5 50 uk