两个表直接查询!帮忙
表user
id, bookid,dates
表info
id, bookid2,isok
要求查询表user中的bookid在表info中的infoid里没相同数据的并且isok=1
为什么一下数据操作会把user中的记录都显示出来,
select bookid from user where not exists(select bookid2 from info where info.isok=1)
问题点数:20、回复次数:6Top
1 楼hdhai9451(☆新人类☆)回复于 2005-02-03 12:51:36 得分 10
//没相同数据
意思表達不清?不相同記錄還是不相同的bookid?根據你的意思,覺得應該這樣寫
select bookid from user where bookid not in(select bookid2 from info where info.isok=1)
Top
2 楼xluzhong(Ralph)回复于 2005-02-03 13:00:23 得分 2
like this?
select bookid from user
where bookid not in(select bookid2 from info)
and isok=1Top
3 楼avirm(我爱电视)回复于 2005-02-03 13:09:35 得分 0
是这个意思,为什么使用 not exists 不行Top
4 楼Qihua_wu(小吴)回复于 2005-02-03 13:23:25 得分 5
select bookid from user a where not exists(select bookid2 from info b where b.isok=1 and a.bookid = b.bookid2)
Top
5 楼JafyLiu(自由的代价)回复于 2005-02-03 13:25:07 得分 3
not exists应该也行,
select bookid from user where not exists(select bookid2 from user.id = info.id and info where info.isok=1)
Top
6 楼JafyLiu(自由的代价)回复于 2005-02-03 13:25:30 得分 0
not exists应该也行,
select bookid from user where not exists(select bookid2 from user.id = info.id and info where info.isok=1)
Top




