Dragon Warrior
Dragon Warrior

Reputation: 327

SQL, SELECT WHERE NOT EQUAL

I have two tables:-

student table

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

studentBatch Table

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

i want students those who are not enrolled in a batch, i want this

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

i tried this code

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

but it didn't work, please help me with this

Upvotes: 0

Views: 139

Answers (3)

Jens
Jens

Reputation: 69440

This should do what you need:

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

Upvotes: 0

SQLChao
SQLChao

Reputation: 7837

try this

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

Upvotes: 0

Alvin Thompson
Alvin Thompson

Reputation: 5448

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

Upvotes: 1

Related Questions