我的两个表的设置如下:
table1
+------+---------+--------------------------------------+ | id | tail | content | +------+---------+--------------------------------------+ | 1 | abc | ... | | 2 | def | ... | | 3 | ghi | ... | | 4 | def | ... | | 5 | jkl | ... | +------+-------+----------------------------------------+
table2
+------+--------+---------------------------------------+ | id | tailID | value | others | +------+--------+---------------------------------------+ | 1 | 2 | 412 | | | 2 | 3 | 215 | | | 1 | 2 | 571 | | | 1 | 4 | 123 | | +------+--------+---------------------------------------+
我想要在一行中获取这两个表中所有的列,满足tail = tailID但不包含具有相同tail的重复行。
对于重复的TAIL,只需要获取具有最大VALUE的单个行即可。
我目前正在使用以下查询:
SELECT table1.tail, table2.other_column FROM table1 INNER JOIN table2 on table1.id = table2.tailID WHERE table1.some_coloum = "a sepecific string" ORDER BY table2.value
但是它会返回许多具有相同tail的重复行。
我只需要具有最高table2的VALUE的重复TAIL的单个行。