Wednesday, February 16, 2011

At my work site, i found the query given below



SELECT 
(
  SELECT COUNT(*)
    FROM ((
            SELECT * FROM &v_ext_table
            UNION
            SELECT * FROM &v_ext_table WHERE 1=2
           ) 
           UNION ALL
          (SELECT * FROM &v_ext_table)
         )
) 
-
(
SELECT COUNT(*)
  FROM (
         SELECT * FROM &v_ext_table
         UNION
         SELECT * FROM &v_ext_table WHERE 1=2
       )
) cnt FROM dual;


.

.

I tried to understand what this query is doing. It is as good as the query given below




select count(*) from &v_ext_table


.

.

I am not able to understand why somebody would write a query like that. If you know then please reply.

No comments:

Post a Comment