book表
id book_name
1 a
2 b
3 c
4 d
read_log表id user_id book_id
1 1 1
2 1 3
3 2 2
-----------
期望结果
2 b
4 d如果要查询出user_id=1没读过的书,求简洁的sql
发过一个类似帖子,以供参考:
http://topic.csdn.net/u/20120705/14/095c12bb-c78f-463d-9027-f28d36779558.html
id book_name
1 a
2 b
3 c
4 d
read_log表id user_id book_id
1 1 1
2 1 3
3 2 2
-----------
期望结果
2 b
4 d如果要查询出user_id=1没读过的书,求简洁的sql
发过一个类似帖子,以供参考:
http://topic.csdn.net/u/20120705/14/095c12bb-c78f-463d-9027-f28d36779558.html
left join (select * from read_log where user_id=1 )b on a.id=b.book_id
where b.book_id is null
from book A
where not exists (select 1 from read_log B where A.id=B.book_id )