Victor Mukherjee
Victor Mukherjee

Reputation: 11025

Selecting entries from a table by checking condition on another table

I have two tables:

Table1

ID    ServiceID  

01     21
02     22
03     23

Table2

ID    Value

01    NULL
02    value2
03    NULL

I want to select those ServiceIDs from Table1 the IDs of which in Table2 do not have a NULL value. The output will be:

ServiceID
22

I can code in C#, but not at all good with SQL. Please help.

Upvotes: 0

Views: 68

Answers (2)

Wim Ombelets
Wim Ombelets

Reputation: 5265

SELECT t1.ServiceID FROM Table1 t1 INNER JOIN Table2 t2
ON t1.ID = t2.ID
WHERE t2.Value IS NOT NULL

Upvotes: 1

Ravi
Ravi

Reputation: 31397

SELECT t1.ServiceID FROM Table1 t1 INNER JOIN Table2 t2
ON t1.ID = t2.ID
WHERE t2.Value IS NOT NULL

Upvotes: 0

Related Questions