sql过滤重复数据
昨天碰到一个Case:
数据库表tbProduct里有数据库
| id | company | product |
| 1 | chenreal | ibm pc |
| 2 | realme | ms mouse |
| 3 | real | 11111 |
| 4 | chenreal | ddddd |
| 5 | chenreal | cccc |
| 6 | realme | qqqqq |
| 7 | realme | cccc |
| 8 | real | 1112222 |
| 9 | chenreal | 88888 |
简单的DISTINCT无法实现的,这里需要用到 GROUP BY
我的解决方法:
select * from tbProduct where [id] in (select max([id]) from tbProduct group by company) order by [id] desc