如表receivefiletag :
receivefiletage_id | doc_rece_id | direction |
1 | 1 | 这是一次 |
2 | 1 | 这是二次 |
3 | 2 | 啦啦啦 |
我们要求重复的doc_rece_id字段只输出其中一条,要获得如下的查询效果:
receivefiletage_id | doc_rece_id | direction |
1 | 1 | 这是一次 |
3 | 2 | 啦啦啦 |
SQL语句如下:
select * from receivefiletag inner join (select min(receivefiletag_id) as receivefiletag_id from receivefiletag where '条件一' group by doc_rece_id order by receivefiletag_id desc) T on receivefiletag.receivefiletag_id= T.receivefiletag_id