SQL,SELECT WHERE NOT EQUAL

时间:2014-06-23 14:12:25

标签: mysql sql

我有两张桌子: -

学生表

std_ID|std_Name
------+--------
1     |  Jhon
2     |  Peter
3     |  Mic
4     |  James

studentBatch表

B_std_ID|B_Batch_ID
--------+-------------
1       |  3
2       |  6
3       |  7

我想要那些没有注册的学生, 我想要这个

std_ID|std_Name
------+--------
4     |  James

我试过这段代码

SELECT std_ID, std_Name FROM student , studentBatch WHERE std_ID <> B_std_ID;

但它没有用,请帮助我

3 个答案:

答案 0 :(得分:1)

select std_id
from student
where std_id not in (select B_std_ID from studentbatch)

答案 1 :(得分:0)

试试这个

select * 
from student a 
where not exists (select * from studentbatch b where a.std_id = b.b_std_id)

答案 2 :(得分:0)

这应该做你需要的:

SELECT std_ID, std_Name FROM student  WHERE std_ID not in (select B_std_ID from studentBatch )