Learning the basics of EXISTS operator

I am learning the basics of EXISTS operator.
create table loans
(acc_id number,
balance number(10,2));
insert into loans
  (acc_id, balance)
values
  (100, 20000);
insert into loans
  (acc_id, balance)
values
  (110, 22000);
insert into loans
  (acc_id, balance)
values
  (120, 7000);
insert into loans
  (acc_id, balance)
values
  (130, 172.99);
SQL> select * from loans;
    ACC_ID    BALANCE
       100      20000
       110      22000
       120       7000
       130     172.99
create table defaulters
  (cust_id number,
   name    varchar2(20),
   acc_id  number);
insert into defaulters
  (cust_id, name, acc_id)
values
  (1,'Vajaal',110);
insert into defaulters
  (cust_id, name, acc_id)
values
  (2,'Mostert',130);
SQL> select * from defaulters;
   CUST_ID NAME                     ACC_ID
         1 Vajaal                      110
         2 Mostert                     130
SQL> select acc_id from loans
  2  where exists(select 1 from defaulters
  3  where loans.acc_id=defaulters.acc_id);
    ACC_ID
       110
       130It just returns all acc_id rows in Loans table which has corresponding ACC_IDs present in defaulters.
On 10gR2 SQL Reference, for EXISTS operator, it says ' An EXISTS condition tests for existence of rows in a subquery' .
Would it be wrong if i say, EXISTS operator can be used when you want to return all rows in the Outerquery which has matching records in the Innerquery.

Would it be wrong if i say, EXISTS operator
can be used when you want to return all rows in the
Outerquery which has matching records in the
Innerquery.Depends on what you understand with "matching".
See following examples:
In this case matching means "<>" i.e. return all loans who have at least one row that differs in defaulters table (of course it returns all loans, because defaulters has 2 rows with different acc_id, BTW look also for NULLs and comparisons involving NULLs)
SQL> ed
Wrote file afiedt.buf
  1  select acc_id from loans
  2  where exists(
  3    select 1 from defaulters
  4*   where loans.acc_id<>defaulters.acc_id)
SQL> /
    ACC_ID
       100
       110
       120
       130See also following query:
SQL> ed
Wrote file afiedt.buf
  1  select acc_id from loans
  2  where exists(
  3    select 1 from defaulters
  4* )
SQL> /
    ACC_ID
       100
       110
       120
       130There isn't any condition at all, so any row in defaulters is "matching" row in this case.
So I'd stick with explanation in documentation this time ;)
Gints Plivna
http://www.gplivna.eu

Similar Messages

  • Please tell the basic procedure and operations for inventory in Sap

    Hello:
          everybody,  please tell me the basic procedure and operations for inventory
    in sap?  couldn't thank you more.                                                                               
    Frank
                                                                                    Best regards

    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/MMIM/MMIM.pdf
    /people/community.user/blog/2007/05/04/physical-inventory-in-material-management
    Physical Inventory Cycle:
    1. Create physical Inventory document MI01
    2. Print physical inventory document MI21
    3. Enter count MI04
    4. Execute difference list MI20
    5. Post with/without differences MI07
    Configuration :
    Inventory Management and Physical Inventory
    Plant Parameters for inventory management
    Goods receipt: Set tolerance limit
    Valuation and Account Determination
    Define Price Control for Material Types
    Account Determination without Wizard
    Rewards if Helpful

  • 55: Photoshop Touch - Learn the Basics tutorial | Ask the Adobe Ones | Adobe TV

    In this episode of Ask the Adobe Ones, Kush explains some of the basics of using Adobe Photoshop Touch on a Samsung Galaxy Note 10.1. Even if you are not familiar with the desktop version of Photoshop, see how easy it is to learn and have fun manipulating and retouching your photos with this Touch App.
    http://adobe.ly/QkHzxD

    kush u just one funny ugly bubble bubble mouth person u look like a ugly scorpion bear old sand paper jean wearin nigga nigga just pop a mollie no sweatin no instagram u dont even know flexion

  • I have just purchased a new iPad from apple and I don't know how to use it. is there somewhere that I can learn the basics

    I have just purchased a new iPad from apple and I don't know how to use it. is there somewhere that I can learn the basics

    Out of a silly curiosity, in what way did Ralph's reply solve your problem? (not that Ralph doesn't deserve recognition, mind you.)

  • Help needed in learning the basics of Java Smart Card and implementation?

    Hello every body,
    I am trying to develop the applications on java contactless smart cards technology.
    Can any body give me the details like how to start?
    What are the required softwares and installation procedure and path settings and etc.?
    I am the beginner in java smart card application development.
    plz help me out

    Dear Friend,
    I would advice to divide learning into two main parts: JavaCard technology and contactless RFID cards. For JavaCard technology you can find useful articles on Sun web-site (developers.sun.com/mobility/javacard/articles/javacard1/). For contactless RFID you can find few useful books at Amazon. Regarding software you need JC development kit. How to install it there is an instrunction in JCDK user guide.
    If it is not a secret what a javacard contactless card you are going to use in your work?
    Yours
    Dmitri

  • Windows 8/8.1 Tutorials / Getting Started / Learning the basics

    If you ever wanted to learn how to use Windows 8 or Windows 8.1 but you were always scared to explore the unknown. This will get you started. Make sure to check out my recommendations.
    If you find or know great tutorials make sure to post them in this thread.
    Here is my selection of the best tutorials
    Windows 8
    Getting around your PC - Microsoft Windows (Official / Recommended)
    Windows 8.1 Power User Guide for Business (PDF)
    Windows 8.1
    Windows 8.1 Essential Training with David Rivers (Recommended)
    Windows 8.1 Preview Tricks & Tutorial Review - Beginners Video Guide
    Windows 8.1 Tutorials by LaptopMag
    Getting Started (Official)
    Both
    Three all new Windows 8.1 video tutorials by Scott Hanselman (Recommended)
    Free Windows 8 Tutorial
    Windows 8/8.1 Tutorials
    Jonas
    Microsoft MVP: Windows Consumer Expert
    Yoga Tablet 2 10 || ThinkPad X1 Carbon (20A7007MPH) || ThinkPad Helix (3698-6EU) || IdeaCentre B540
    Twitter: @jonashendrickx

    You need to boot from an OS X installer disc compatible with this model's hardware or you must connect it by Target Disk Mode - Target Disk Mode - so you can re-partition and reformat the hard drive before you can install Mountain Lion on it or any other version of OS X. Here's the process:
    Drive Partition and Format
    1. Boot from your OS X Installer Disc. After the installer loads select your language and click on the Continue button.  When the menu bar appears select Disk Utility from the Utilities menu.
    If you are preparing an external or a non-startup drive, then open Disk Utility in your Utilities folder.
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area.  If it does not say "Verified" then the drive is failing or has failed and will need replacing.  SMART info will not be reported  on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Click on the Options button, set the partition scheme to GUID then click on the OK button. Set the format type to Mac OS Extended (Journaled.) Click on the Partition button and wait until the process has completed.
    4. Select the volume you just created (this is the sub-entry under the drive entry) from the left side list. Click on the Erase tab in the DU main window.
    5. Set the format type to Mac OS Extended (Journaled.) Click on the Security button, check the button for Zero Data and click on OK to return to the Erase window.
    6. Click on the Erase button. The format process can take up to several hours depending upon the drive size.

  • Learning the basics

    Can anyone tell me how, via Actionscript, one can get an
    object to move via the press of a button to a desired reference
    point and scale up or down when it does so?
    This is probabably really basic but for a newbee like me it
    would probably be easier carrying this computer to the top of
    Everest!
    Thank you :)

    my_btn.onRelease = function() {
    my_mc._x = 473;
    my_mc._y = 382;
    my_mc._width = 38;
    my_mc._height = 329;
    you can also use the Tween and Easing class for smooth
    transitions
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    my_btn.onRelease = function(){
    var tw:Tween = new Tween(my_mc, "_x",
    mx.transitions.easing.Strong.easeOut, 100, 473, 1, true);
    var tw2:Tween = new Tween(my_mc, "_y",
    mx.transitions.easing.Strong.easeOut, 290, 387, 1, true);
    where the first number is starting point, second is ending
    point, third is how long it takes, and true=in seconds false=in
    frames. look in help files there are more tweens other than
    Strong....Back, Elastic, Regular... theres easeOut easeIn
    easeOutIn... you can do all this will all properties _width _height
    _alpha blah blah... have fun

  • I've learned the basics, what's the next step?

    Hi guys! I've just finished a book (Java - A Beginner's Guide) and some of the tutorials on sun.com and I'm wondering what's the next step?
    The reason I'm learning Java is to get a programming job somewhere in the future. I'm in the medical field and I want to change careers. I always loved computers and technology!
    I've browsed the job market in our country and a lot of them are looking for J2EE capable people. How do I make the transition to J2EE? Is there a good book available for learning it? How should I prepare next?
    Thanks!

    djshinton wrote:
    Sounds to me that you want to learn J2EE to get a job in Java. The problem with J2EE is that knowing it alone wont get you a job doing it. Also, programming J2EE requires that you know J2SE, so make sure you are extremely comfortable with J2SE before moving on.I agree. You should focus on understanding the compiler, runtime, and core API well before moving on. You should write several applications (even a couple advanced level apps) before moving out of core. But you don't need to do a lot with stuff like Swing or whatever. I would touch JDBC and I'd also get some understanding of threads.
    If you want to code J2EE you typically have to specialize on something. There are many roles in a J2EE project; for example, do you want to do presentation logic using JSP, code EJBs in the business layer, or administer and deploy J2EE applications? In addition, employers typically use a particular application server (i.e. Websphere, Weblogic, JBoss, Geronimo) so you will have to get familiar with them.I disagree for the most part. For the past 7 years of doing J2EE contracts (probably a dozen projects or so) it's rare that the roles are divided. Occasionally you have a web developer that will do the graphics and layout and design of web pages, but the Java/J2EE developer usually does everything else. It's not uncommon to have someone who primarily does server configurations and deployments, but you will need to learn that soon enough. Most of the time that responsibility is shared.
    I would recommend reading Mastering EJB. You can download a free copy at http://www.theserverside.com/tt/books/wiley/masteringEJB. You should be able to use it as a guide to develop some test applications on a free application server such as JBoss, Geronimo, Glassfish, or WebSphere Community Edition.
    I haven't worked on EJB's since 2003. Nobody seems to use them. Some people are getting back into it now that it's EJB3 but nobody I know. Save EJB for last. Focus on JSP/Servlets, XML, JNDI, Web Services, maybe JMS...

  • New computer, new PSE7, where can I learn the basics or uploading & organizing?

    I have used PSE3 for years. With a new laptop in hand and PSE7 I have a chance at "doing it right".  With PSE7 how do I find basic tutorials on getting started?  On my previous computer and using PSE3 I had my images in both the PSE organizer and "My pictures".  I don't want to have multiple places storing images on my computer.   How do I go through the very basics of importing pictures and organizing them? Thanks!

    photodonna,
    The picture files are stored wherever you put them - e.g. MyPictures, Documents. The organizer does not store the pictures.
    You see thumbnails.
    There was published an excellent book, Organize Your Photos with Adobe Photoshop Elements 3, by Michael Slater. Unfortunately he has not seen fit to update this book, but the general principles should hold for the more recent version of Elements. One of the contributors to this forum refers to the book quite frequently. It is available for $2.75!
    http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&field-keywords=organize +your+photos&x=17&y=14

  • Can anyone recommend a good "How To" Book. I have switched to a MacBook pro 15 inch. and I woiuld really like to learn the basics and get the most out of my Mac.

    I want to be able to get the most out of my MacBook pro. Any suggestions on a good book to read?

    Switching to a Mac For Dummies, 2nd Edition

  • Understading EXISTS operator

    Version:10gR2
    I am an intermediate user of SQL. I was just brushing up on the concepts of EXISTS operator.
    I was going through the following thread regarding EXISTS :
    Re: learning the basics of EXISTS operator
    I am including the example in this post since it is not very readable in the original post.
    create table loans
    (acc_id number,
    balance number(10,2)
    insert into loans (acc_id, balance) values (100, 20000);
    insert into loans (acc_id, balance) values (110, 22000);
    insert into loans (acc_id, balance) values (120, 7000);
    insert into loans (acc_id, balance) values (130, 172.99);
    create table defaulters
    (cust_id number,
    name    varchar2(20),
    acc_id  number
    insert into defaulters (cust_id, name, acc_id) values (1,'Vajaal',110);
    insert into defaulters (cust_id, name, acc_id) values (2,'Mostert',130);
    commit;
    select acc_id from loans
    where exists(select 1 from defaulters where loans.acc_id=defaulters.acc_id);This is what user gintsp has said about inner query (subquery)
    "Exists returns true as soon as subquery returns at least one row.It is not relevant whether it returns one column or a row"
    -- gintsp
    By "one column", he meant multiple rows. Right?
    My understanding on what gintsp said (forgive me if this is a bad example)
    If i have a parent table called ITEM_MASTER and a child table called ITEM_DTL
    select item_id from item_master im
    where exists(select 1 from item_dtl id where im.item_id=id.item_id and id.year_n =2011);Since item_dtl is the child table there will several records matching one particular item_master.item_id, but Oracle won't return all the matching records (ie.Duplicates) because EXISTS will only check if the inner quer retuns at least one row; if it does, it will return only one matching item_master.sku_id from the outer query.
    By saying "It is not relevant whether it returns one column or a row" , did gintsp mean that EXISTS operator won't return duplicates ?
    Edited by: Jack on Feb 25, 2011 7:52 AM
    Edited the line "it will return only one matching item_master.sku_id from the outer query"

    Hi,
    It sounds like you understand the EXISTS operator correctly.
    As Etbin said, EXISTS is a condition. Conditions alwyas evaluate to (or "return") one of the 3 possible boolean values: TRUE, FALSE or UNKNOWN. (EXISTS always evaluates to either TRUE or FALSE, and never to UNKNOWN.) It doesn't matter what columns are in the sub-query. For sytnatic reason, you must have a SELECT clause with at least one column, so a lot of people use
    EXISTS ( SELECT NULL FROM ...)to emphasize that the columns in the SELECT clause are meaningless.
    Jack wrote:
    Version:10gR2Thanks; it's always good to know what version you're using.
    I am an intermediate user of SQL. I was just brushing up on the concepts of EXISTS operator.
    I was going through the following thread regarding EXISTS :
    Re: learning the basics of EXISTS operator
    One of the many quirks of this site is that it tends to mangle URLs if you edit the message. It looks like that happened to the link in your message; it now ends with a # sign, which people will have to remove before they can use the link. (You can edit your message again, and do it once for all.)
    I am including the example in this post since it is not very readable in the original post.Yes, that thread isn't the best explanation of EXISTS for several reasons. Don't spend too much time on it.
    ... This is what user gintsp has said about inner query (subquery)
    "Exists returns true as soon as subquery returns at least one row.It is not relevant whether it returns one column or a row"
    -- gintsp
    By "one column", he meant multiple rows. Right?It's hard to say what Gints meant. The columns that the sub-query is looking for are completely irrelevant; it doesn't matter how many columns there are.
    The whole purpose of EXISTS is to tell you if the sub-query returns any rows or not, but it makes no difference if the sub-query returns 1, 2, 3, or 123,000 rows: all that matters is wheter it returns 0 rows or more. Oracle documentation has always said that it stops looking after it finds one row, meaning that the optimizer is as efficient as it can be. In recent versions of Oracle, the optimizer may re-write the query entirely: if you code an EXISTS statement, it may actually execcute a join that produces the same results, if it thinks the join will be faster.
    My understanding on what gintsp said (forgive me if this is a bad example)
    If i have a parent table called ITEM_MASTER and a child table called ITEM_DTL
    select item_id from item_master im
    where exists(select 1 from item_dtl id where im.item_id=id.item_id and id.year_n =2011);Since item_dtl is the child table there will several records matching one particular item_master.item_id, but Oracle won't return all the matching records (ie.Duplicates) because EXISTS will only check if the inner quer retuns at least one row; if it does, it will return only one matching item_master.sku_id from the outer query.Right. All that matters is "Does the sub-query find a row or not?" You can be sure it won't wast any effort counting the exact number of matching rows. It knows that it only has to find one, since it woun't be passing back any anyformation about what it found, other than the fact that it found something.
    By saying "It is not relevant whether it returns one column or a row" , did gintsp mean that EXISTS operator won't return duplicates ?No, duplicates don't matter at all, and I don't think Gints was saying that they did.

  • Bug in View Criteria for EXISTS operator

    Hello!
    I have two VO:
    DEP (ID, TITLE, STATUS)
    EMP (ID, ID_DEP, NAME)
    and viewlink DEP.ID <- EMP.ID_DEP
    in DEP VO i create view criteria and add two items:
    * DEP.STATUS <> 1000
    * the EMPVO with EXISTS operator (and after that add condition EMP.NAME contain :nName (bind var))
    start app, set "john" in search field, press button "search" and in debug console i found sql for searching in DEP:
    SELECT *
    FROM (SELECT DEP.ID,
    DEP.TITLE,
    FROM DEP DEP
    where (DEP.STATUS is null OR DEP.STATUS <> 1000)) QRSLT
    WHERE ((((EXISTS (SELECT 1
    FROM EMP EMP
    WHERE ((UPPER(EMP.NAME) LIKE
    UPPER('%' || :nName || '%')))
    AND (ID = EMP.ID_DEP))))))
    in last row present error, must be:
    AND (QRSLT.ID = EMP.ID_DEP))))))
    coz if no "QRSLT", sql parser think what need compare EMP.ID and EMP.ID_DEP.
    Present in JDeveloper 11.1.1.2.0, 11.1.1.3.0.

    We have implemented our own ViewCriteriaAdater (derived from oracle.jbo.server.OracleSQLBuilderImpl) and some custom properties to handle this. Overwrite the getFormattedRHSCompareFragment to your needs.
    Btw. I think this posting should go to the JDev forum.

  • How can learn the very basics of Pixelmator?

    How can I learn the very basics of using Pixelmator?   I have no graphic arts experience beyond WOrd Art which I've used to design t-shirt graphics.    Although I had been encouraged to by Photo Shop, I wanted a smaller $ step into graphics art and was introduced to Pixelmator.
    But I don't even know enough about how to start creating my ideas....e.g. how to even create artful text......    Pixelmator has a good learning site, but all of their tutorials seem to assume a basic knowledge of this kind of software.
    My sister suggested I try to hook-up with a tutor through an Apple Forum....
    Suggestions please?!

    The folks at PixelmatorTutorials.net have in my opinion the best tutorials to date for those who want to learn image editing. They have a series of tutorials called back to basics and these go into the details of image editing. Explaining everything from what a pixel is, to how it gets its color etc. They also explain the app itself in detail. I'd recommend following them. They usually pubilish 1 to 2 tutorials a week. They have some handy tips in every tutorial I watched so far. Like shorcuts that I never knew existed and are not even mentioned in the Pixelmator manual.
    The link: http://pixelmatortutorials.net
    Good luck.

  • Problem with copying to external drives 10.8.3 "the operation can't be completed because an item with the name .ds_store exists"

    After upgrading from 10.7.5 to 10.8.3 I cannot copy certain folders to any external drive. the operation can't be completed because an item with the name .ds_store exists. I have seen this problem in discussions for many years with no real solution. Does anyone have a resolution? Please help. This is very frustrating as I work in two locations and copy folders back in forth all the time.

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of the test is to determine whether the problem is caused by third-party software that loads automatically at startup or login, or by a peripheral device. 
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including Wi-Fi on certain iMacs. The next normal boot may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin. Test while in safe mode. Same problem? After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of the test.

  • When I sign in to Gmail in FF I get this mess -Error undefined If this problem persists, try reloading the page, or using the basic HTML version. Learn More.

    When I sign in to Gmail in FireFox I get this mess -Error undefined If this problem persists, try reloading the page, or using the basic HTML version. Learn More.

    Reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
    *Press and hold Shift and left-click the Reload button.
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Command + Shift + R" (MAC)
    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do not click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

Maybe you are looking for

  • Windows Vista not recognizing ZEN Mi

    I upgraded to Windows Vista 32-bit ultimate, and my ZEN Micro is not recognized. I have let Vista search for drivers online automatically, but it finds no solution. Creative says there is nati've support, so why is my ZEN not recognized?

  • Best Practice for link to WebdynPro page in welcome page

    Hi Experts,     I am new in SAP Portal. I need some guidance from you guys. I have a requirement to create welcome page which is JSP and has a link to a WebdynPro page. I have to put the url in JSP file. So i do not know what kind of URL i should put

  • Email stops synching after 15 minutes (when it locks the screen). Any thoughts?

    I got the Droid 2 yesterday.  Email account (syncs to corporate email) works fine until the device goes to sleep (or what ever it does after 15 minutes that locks the screen then you have to enter a PIN to wake it up again).  Even after entering the

  • WDS and PXE

    I'm trying to set up WDS on server2008r2. the dhcp server is runnning server 2003. I have option 66 enable pointing to 172.18.4.23 and option 67 boot\x64\boot.wim  when i try to boot up a client to install the first instance to build my company image

  • How to avoid printer name prompt while calling Smartform

    Hi All, I am calling smartform FM from my program. I am passing following settings in Output-Options and Control-Parameters: wa_outputoptions-tddest = 'LP01'.  "Printer name wa_outputoptions-tdnewid = 'X'.     "New request wa_controlpara-device = 'PR