表A
c_id name
1 a
2 b表B
id c_id title
1 1 天上人间来的
2 1 香格里拉来的
3 2 故宫来的
4 2 秦陵来的联合查询,请问怎样查询去掉去表B中c_id重复的记录呢,B表中只查询出一条匹配最新(根据id倒序即可)记录。
显示结果要如下:
c_id name title
1 a 香格里拉来的
2 b 秦陵来的注:不用group by
c_id name
1 a
2 b表B
id c_id title
1 1 天上人间来的
2 1 香格里拉来的
3 2 故宫来的
4 2 秦陵来的联合查询,请问怎样查询去掉去表B中c_id重复的记录呢,B表中只查询出一条匹配最新(根据id倒序即可)记录。
显示结果要如下:
c_id name title
1 a 香格里拉来的
2 b 秦陵来的注:不用group by
where not exists(select 1 from A b where t.c_id=b.c_id and t.id<b.id);
[征集]分组取最大N条记录方法征集,及散分....