Solved

oracle query question

Posted on 2011-03-09
3
402 Views
Last Modified: 2012-05-11
experts.. I have a query in one of the packages here at work and want to know what it means

The query is
                         (SELECT 'Y'
                            FROM table_a a, table_b b
                           WHERE a.id= b.id
                                 AND a.del_ind = 'N'
                                 AND 0 =
                                        (SELECT COUNT (1)
                                           FROM table_c c
                                          WHERE a.SRC_ID =
                                                   c.SRC_ID
                                                AND c.PRD_ID =
                                                       ANY (SELECT prd_id
                                                              FROM product p
                                                             WHERE p.PRD_ID IN
                                                                      ('FSCC1',
                                                                       'FSCC2')))
I want to know what 0= means in SQL and where can such queries be used
0
Comment
Question by:chickanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
CarlsbergFTW earned 175 total points
ID: 35083561
0 stands for the count that is done within the sub-query , this means that if COUNT (1) returns 0 then the condition is met. else result is ignored.
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 175 total points
ID: 35083565
This is just checking the returned count from the sub select.  The outer query will only return rows when the inner select returns 0 rows.

These are typically called inline views.  You can use them just about anywhere.

for example:
select 'Hello', (select 'World' from dual) as col1 from dual;
0
 
LVL 5

Expert Comment

by:jaiminpsoni
ID: 35084010
When you say count(*) = 0, it means you are checking for non existance of records with specifying conditions.

So, this is equivallant to NOT EXISTS clause of Oracle...

Please look at http://www.techonthenet.com/sql/exists.php for more information on exists/not exists

So for 0 and >0 you may use NON EXISTS and EXISTs respectively.

But suppose you need to figure out that there should be exactly 5 matching records returned by such subquery, you have to use Count(*) = 5

One very generic example of this is

suppose you want to find out the fifth highest paid saialry... you use this

SELECT DISTINCT (a.sal) FROM EMP A WHERE 5 = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);

Thanks,
Jaimin Soni
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to recover a database from a user managed backup

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question