Reputation: 3626
I got the table structure as follows
-------------------------------- id processId newId value -------------------------------- 1 1 1 a 2 1 2 b 3 1 4 c 4 2 5 d --------------------------------
and
------------------------ id processId mapnewId ------------------------ 1 1 1 2 1 2 ------------------------
How should i get the value "c" (that means i should get the value which is not mapped to "1" in the second table) from the table in which the id mapped.
Upvotes: 1
Views: 84
Reputation: 19882
Here is the answer for single record
Select
t1.processId,
t1.newId,
t1.value,
t2.processId,
t2.mapnewId
FROM t1
LEFT JOIN t2
ON t1.processId = t2.processId and t1.newId = t2.mapnewId
where t1.processId = 1 and t2.processId is null
Upvotes: 1
Reputation: 71
As per the my understanding you are looking for some query which will return the rows which are not der in second table.. If that's fine, then "Except" operation will help you out with the same :
The SQL EXCEPT clause/operator is used to combine two SELECT statements and returns rows from the first SELECT statement that are not returned by the second SELECT statement. This means EXCEPT returns only rows which are not available in second SELECT statement.
Please refer: http://www.tutorialspoint.com/sql/sql-except-clause.htm
Upvotes: 0