请教数据库查找出错
SELECT C_Score,S_Name,S_ID,E_Title FROM Scores,Teachers,Students,Essay WHERE T_ID='1' and Teachers.T_Group=Students.S_Group and Students.S_ID=Essay.E_SID not Exists{SELECT * FROM Scores,Teachers,Students WHEREScores.C_TID=Teachers.T_ID and Scores.C_SID=Students.S_ID)--这种语法上就应该没有问题了,但是估计你也很难得到你想要的结果。SELECT C_Score,S_Name,S_ID,E_Title FROM Scores,Teachers,Students,Essay WHERE T_ID='1' and Teachers.T_Group=Students.S_Group and Students.S_ID=Essay.E_SID and not Exists --少个and( --之前括号确实不对SELECT * FROM Scores,Teachers,Students,Essay WHERE --这个位置少个表Scores.C_TID=Teachers.T_ID and Scores.C_SID=Students.S_ID)
[解决办法]
--> 测试数据: @adeclare @a table (id int)insert into @aselect 1 union allselect 2 union allselect 3--> 测试数据: @bdeclare @b table (col int)insert into @bselect 2 union allselect 3 union allselect 4--> 测试数据: @cdeclare @c table (c int)insert into @cselect 4 union allselect 5 union allselect 6--> 测试数据: @ddeclare @d table (d int)insert into @dselect 3 union allselect 4 union allselect 5--四个表内连接,很容易没有结果的select * from @a a,@b b,@c c,@d dwhere not exists(select * from @a a,@b b,@c c,@d d where b.col=c.c)
[解决办法]
你把exists理解成in了
按照你的意思用except就应该可以了。