请问一个简单的SQL有关问题

请教一个简单的SQL问题

表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


SQL code

select * from B t
where not exists(select 1 from A b where t.c_id=b.c_id and t.id<b.id);


mysql> select mm.c_id ,aa.name,mm.title from (select bb.* from B bb where not ex
ists (select 1 from B where bb.c_id = c_id and bb.id<id)) mm ,A aa where mm.c_i
d = aa.c_id;
请问一个简单的SQL有关问题

相关文章:

你感兴趣的文章:

标签云: