两个表
table1 table2
id caption acid username
1 qqqq 1 aa
2 eeee 2 aa
3 dddd 3 aa
4 fdff 2 bb
5 sdfee 4 bb
6 ttttt 6 bb
现在table2中用户aa有3条,要查询出列出table1中的4,5,6
table1 table2
id caption acid username
1 qqqq 1 aa
2 eeee 2 aa
3 dddd 3 aa
4 fdff 2 bb
5 sdfee 4 bb
6 ttttt 6 bb
现在table2中用户aa有3条,要查询出列出table1中的4,5,6
select * from table1 where id not in (select acid from table2 where username='aa')
table1
id caption
1 模块1
2 模块2
3 模块3
4 模块4
5 模块5
6 模块6
table1是用户权限管理表TABLE2
id username
1 admin
2 admin
3 admin
2 guest
4 guest在table2表中,记录着用户admin和guest所拥有的权限(admin有table1中的记录1、2、3,guest有2、4)
现在要查询出admin在table1表中所没有拥有的权限
查询后,用户admin的结果如下:
id caption
4 模块4
5 模块5
6 模块6各位大虾们,看懂没有!小弟表达能力差,请理解啊
你的table1,table2之间总该有个关键字进行联接的吧,而你的里面id,都好像像是各自的主键
不懂,不懂
select table1.id,table1.caption
from table1 where table1.id not in (select id from table2 where table2.caption='admin')
同意
zxf_feng(阿日)