如何选择重复字段的最新ID

时间:2019-07-04 05:13:59

标签: mysql vb.net mysqli

我的MySQL查询有什么问题,如果执行该查询,我只会得到1行,但是指定表中有很多数据。表中有很多重复的OAno,我想选择最新的ID。

SELECT * FROM  hct_info_oa WHERE OAno IN (SELECT * FROM (SELECT DISTINCT OAno FROM hct_info_oa ORDER BY hct_id_po DESC LIMIT 1) as t1) LIMIT 50

表hct_info_oa

hct_id_po | 1 | 2 | 3 | 4 | 5

OAno ------ || 266 | 266 | 266 | 522 | 522

预期输出:

hct_id_po | 3 | 5

OAno ------ | 266 | 522

0 个答案:

没有答案