开发者

Query not giving output correctly

please tell me actually i want only delete entries.but i did not get in this query I have two table the same entry is present in other table also. and i have deleted few enteries from first table and i want to see that deleted开发者_StackOverflow entry using that query.but it is not giving correct output.

select *
from branch a, course b
where a.courseid = b.courseid(+)
and b.courseid(+) is null;


Your query is nearly right; this would work:

SELECT *
FROM branch a, course b
WHERE a.courseid = b.courseid(+)
  AND b.courseid IS NULL;

This query is equivalent to the following query with ANSI join syntax:

SELECT *
FROM branch a
LEFT JOIN course b ON a.courseid = b.courseid
WHERE b.courseid IS NULL;

However it is a convoluted way to get rows from branch that are not in course (anti-join). The following query should produce the same plan and is easier to read:

SELECT * 
FROM branch b 
WHERE NOT EXISTS (SELECT NULL 
                  FROM course c 
                  WHERE c.courseid = b.courseid)

If course.courseid and branch.courseid are NOT NULLABLE, the following query is equivalent and is even easier to understand:

SELECT * 
FROM branch b 
WHERE b.courseid NOT IN (SELECT c.courseid FROM course c)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜