Finding the first X with exactly one Y

Suppose you have a table DEPT_EMP with columns DEPT and EMP and there can be many employees in a department.
I want to find all the departments with exactly one employee and also the sole employee's name.
How would you recommend doing it. The one way I am thinking of is to perform a self-join of DEPT_EMP with itself:
SELECT D1.DEPT, D1.EMP
  FROM DEPT_EMP D1
  LEFT JOIN DEPT_EMP D2 ON (D2.DEPT = D1.DEPT AND D1.EMP <> D2.EMP)
  WHERE D2.DEPT IS NULL;In theory it should work, but I haven't tested it. Are there other ways?
Edited by: user10936714 on Jul 1, 2009 12:44 PM

This will give your all the details of the employee
SQL> select * from emp
  2  where deptno in (
  3  select deptno
  4  from emp
  5  group by deptno
  6  having count(*) = 1 )
  7  /
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
      7369 SMITH      CLERK           7902 17-DEC-80        800                    99OR
Without Using a group by clause
SQL> select ename , deptno
  2  from (
  3  select ename , deptno , count(ename) over ( partition by deptno ) k
  4  from emp  )
  5* where k =1
ENAME          DEPTNO
SMITH              99SS

Similar Messages

  • IDCS4 - [JS] - How to find the Last paragraph with only One word - Reg.

    Dear All
      Here I have a big doubt!.
          I checked Total number paragraphs in the Text Frame and Each paragraph having only 1 words and then immediatly checked with words. Its only having less than 6 characters or not, Like that I checked and throw the log file.
    But I can't add this content in the file....
    //================= Here my coding ===========================//
             var myDoc = app.activeDocument;
             var myPages = myDoc.pages;
             var myTextFrame;
             var myParagraph;
             var myParaLine;
             var myParaWord;
             var Pagecount= 1 ;
             var paraCount = 1;
             var myChars;
             log1 = myDoc.name.split(".indd")[0];
                FilePath = myDoc.filePath;
               aFile = File(FilePath + "/" + log1 + "_LastLineWords"+ ".log");
               var today = new Date();
               aFile.open("w");
               aFile.seek(0,2);
              aFile.write("\n"+"  Last Line only 2 words logs       "+"\n");
              aFile.write("         - - - - - - - - - - - - - - - -               "+"\n\n");
              aFile.write("\n"+String(today+"\n"));
              aFile.close(); 
             for(var i=0; i<myPages.length; i++)
              myTextFrame = myPages[i].textFrames;
               for(var j=0; j<myTextFrame.length; j++)
                  myParagraph = myTextFrame[j].paragraphs;
                 for(var k=0; k<myParagraph.length; k++)
                    if(myParagraph.length >= 2)
                    myParaLine = myParagraph[k].lines;
                  for(var m=0; m<myParaLine.length; m++)
                     if(myParaLine[m].words.length < 2 )
                       myChars = myParaLine[m].words;
                     for(var n=0; n<myChars.length; n++)
                       if (myChars[n].characters.length < 6 )
                        aFile.open("e");
                        aFile.seek(0,2);
                        app.select(myChars[n])
                        var mySel = app.selection[0];
                        $.writeln(mySel.contents);
                        $.writeln(mySel);
                        aFile.write("\n"+"Contents :"+"\t"+mySel.contents+"\n");
                        aFile.write("\n"+"Line No. of the Content  :"+"\t"+ myParaLine.length+"\n");
                        aFile.write("\n"+"Pargraph No. of the Content  :"+"\t"+ paraCount+"\n");
                        aFile.write("\n"+"Page No. of the Content   :"+"\t"+ Pagecount+"\n");
                        aFile.close();
                   paraCount +=1;
               Pagecount +=1;
       //======================================== Execute the Log File =================================//
                if(aFile.length != 0)
                aFile.execute();
                 else
                 var myDelFile = File(FilePath + "/" + log1 + "_LastLineWords"+ ".log");
                 myDelFile.remove();
                   exit(0);
    //========================== End of the Script =======================================================//
    The $.writeln(mySel); throws [Object Text]... How to write the contents in my Log file.
    This is working in non-xml contents but this is not working in xml contents. Please anybody can check the above code and please give me the suggestion....
    Please any one can help me, I will appreciate....
    Thanks & Regards
    T.R.Harihara Sudhan 

    Welcome to the Apple discussions.
    These discussions are user-to-user. Apple generally doesn't monitor the discussions.
    My Turkish language skills are non-existant, however, you can use this to find an Apple store close to you: http://www.apple.com/uk/buy/locator/ (you choose your country in the locator) . It may be as easy as returning it to a local store. In some countries you have a short time period to return anything bought from Apple (for example, 14 days in the US). If that doesn't work, you want to contact Apple customer service. Unfortunately, this is where I was unable to maneuver through the Turkish Apple site, due to not knowing the Turkish language.

  • Find the first occurance of a word

    I have a script which finds and counts ALL occurances of a word.
    I need the script to find the FIRST instance of a word only.
    Can any one please advise how to modify the script to find the first instance of the word?
    Script as follows:
    var numWords = this.getPageNumWords(0);
    for (var i=0; i<numWords; i++)
    var ckWord = this.getPageNthWord(0,i);
    if ( ckWord == "MATERIAL")
    /*Script will go here based on finding the first instance of the word "MATERIAL"*/
    I have tried var CKWord = this.getPageNthWord(0,0); but console reports back is UNDEFINED?

    Thanks for your help.  Script now returns the first occurance of the word "MATERIAL".
    I know have to add to the script to find the SECOND OCCURANCE of the word "ISSUED".
    Can you please advise how I would code the script for this, ie would this have something to do with the break command?
    var numWords = this.getPageNumWords(0);
    for (var i=0; i<numWords; i++)
    var ckWord = this.getPageNthWord(0,i);
    if ( ckWord == "ISSUED")
    var coord = this.mouseX;
    var annot = this.addAnnot({
    page: 0,
    type: "Stamp",
    name: "AppStamp",
    rect: [coord+1000, 2300, 30, 2820],
    rotate: 90,
    AP: "#C94cHAFFa42U1gTH5Tug5C" }); 
    /*break; how can this be modified to break for the second occurance of the word "ISSUED"?*/

  • HT203167 i have purchased 100 songs in last 2 years on itunes  now i am able to find the first 50 songs i am using the original id in all my devices.i even got the invoice of my purchase where can find them all?

    i have purchased 100 songs in last 2 years on itunes  now i am able to find the first 50 songs, i am using the origial id in all my devices.i even got the invoice of my purshace where can find them all?
    ITS NOT EVEN SHOWING UP IN PURCHASED SECTION

    1. iTunes won't offer cloud downloads for songs that it "thinks" are in your library, even if it "knows" the files are missing. If you've exhaustively searched for the missing files and there is no prospect of repair by restoring to them to their original locations, or connecting to new ones, then delete that tracks that display both the missing exclamation mark and are of media kind Purchased/Protected AAC audio file. Don't hide from iTunes in the cloud when asked, close iTunes, then reopen. You can download from the cloud links or iTunes Store > Quicklinks > Purchased > Music > Not on this computer > All songs > Download all.
    2. Why? Not sure, perhaps 3rd party tools or accidental key presses combined with previously hidden warning messages when trying to organize the library. There is a hint that using the feature to downsample media as it is synced to a device may also be involved, though I've not replicated it. Whatever the reason a backup would protect your media.
    tt2

  • UDF for Find the First letter from Input

    Hi Masters,
    I want find the first letter from input, Can any one help me on this..UDF or any solution.
    Ex: E2HB means - Alpha Letter is the first
    Ex: 1234 means - Number is the first
    Thanks,
    Siva

    Hi Siva,
                I just want to clarify this doubt, you want the first character of the string you pass to the UDF i.e if input="E2HB"  output="E"   and if input="1234"   output="1". If my assumption is correct you can try the UDF "firstChar" I have shown below this gives exactly the output you want
    public class firstLetter {
         public static String firstChar(String s)
              if(s==null)
                   return null;
              if(s.equals(""))
                   return s;
              String t="";
              t+=s.charAt(0);
              return t;
         public static void main(String[] args) {
              String s1="E2HB",s2="1234";
              s1=firstChar(s1);
              System.out.println(s1);
              s2=firstChar(s2);
              System.out.println(s2);
    Regards
    Anupam

  • Fail to run my first Servlet with Sun ONE Studio 4 Update 1 (+ bi Tomcat)

    Hello !
    I failed to run my first Servlet with Sun ONE Studio 4 update 1 ( with built in Tomcat)
    I think that I followed most of the online instructions,
    so I successfully run a JSP file,
    but I failed with my first servlet:
    The error message is:
    "Standard Wrapper[:MyServlet]: Marking servlet MyServlet as unavailable
    javax.servlet.ServletException: Wrapper cannot find servlet class com.hemmerling.myservlet.MyServlet
    or a class it depends on
    So please don�t ask me for the code of the servlett ( simply taken from a book),
    but tell me why the one-and-only servlett was not found. what might I have done wrong, if I did everything I did to run the JSP file, too ?
    Of couse I copied the file into the "Classes" directory of the Webmodule ( WEB-INF ) and "processed" it, so that I was able to execute it.
    Any suggestions ?
    Tia
    Sincerely
    Rolf

    Tough to say, but try:
    1. Put the servlet in a package. If you're using the default package (class file in WEB-INF/classes directory, then Tomcat may not find it.
    2. Check out web.xml to ensure the <servlet> and <servlet-mapping> entries are correct.
    3. Make the servlet as simple as possible so you're sure that it is the servlet itself that cannot be found and not some other class that it uses.
    Good Luck

  • Finding the first unused number in a column

    I am attempting to write a single SQL statement that can find the first unused number for a column. For example, for a column called BLOCKID, that contains these values...1,2,3,4,6,7,8...I would like to be able to insert a record with BlockID equal to 5. I can do this by writting a loop, but that seems quite inefficient (may have to loop hundreds of times or more to find the first available hole).
    Any ideas? Thanks, Kieren
    null

    Here's one way
    1. Get a list of row numbers for the table
    2. Add an item to the list for 1 more than the largest id
    3. Remove from the list all numbers already used
    4. Use the smallest value of the list that is left.
    As a query this would be:
    SELECT MIN(BLOCKID) FROM
    (SELECT MAX(BLOCKID) + 1 BLOCKID
    FROM mytable UNION ALL
    SELECT ROWNUM BLOCKID
    FROM mytable MINUS
    SELECT BLOCKID FROM mytable
    Needless to say there should be a primary key or index on the BLOCKID column of 'mytable'.
    Good luck!
    null

  • IDOCS - Finding the first error message when reprocess has been done 17000 times

    I was hoping for some assistance. We have an automated reprocessing of our iDocs in one interface. I would like to find the first error message at status 51 in order to see the failure messge. Since the idocs have been reprocessed so many times, it cannot be found in the iDoc handler. Please advise if you have tips.

    This message looks like homemade. And the message will not change, no matter how often you repost the same IDOC without having changed anything.
    So you should at least see the message number to this message in the EDIDS table
    You can search SCN using this number, you can search for OSS notes with this number, or you get active yourself in SAP and check the where used list from SE91 transaction to know in which program this error is triggered and under what circumstances

  • RAID Fails to find the first device

    Hello all.
    This is my first post to the forum. I did a brief search but i couldn't find any good results, so i tought i'd post my prob here.
    I have an MSI K7N2 Delta2-LSR motherboard, with a 450W PSU (i don't have any more info on that yet), 2x512MB RAM DDR 400 (no more info on that one yet either), 2x120GB SATA WD HD, 1xDVD TEAC, 1xDVD+-RW SONY DL, 1x1.44MB FDD, an ATI RADEON 9600 PRO ALL-IN-WONDER VGA card on an nForce chipset.
    The first HD has WinXP installed on it with the raid drivers installed properly. The second HD has Mandrake 10.1 Linux installed on it.  They are installed as separate arrays.
    The problem I'm having is that while I'm working in Windows, after a while the computer completely freezes. The only possible way out of it is to reset the machine. After I do that, at the boot screen, it fails to find the first HD (the one with WinXP on it). If i turn it off for let's say 5 minutes, and boot up, it detects the HD again and goes on loading windows. After I log in i have at maximum 5 minutes before it freezes again.
    It does this every time. The more time I leave my PC turned off, the longer time it will take to freeze again when I'm logged in WinXP. I formatted the HD many times, installing every possible combination of my drivers but the problerm persists. Although it has never happened anything like that in Linux.
    Could it be the RAID Controller (onboard), the WD HDD, or the Motherboard in general?
    What can I do to find out what the problem is? And if possible, how to solve it?
    If more info is needed, I will update the info of my pc as soon as I get back home.
    P.S. I cheched the WD HDD, using WD tools like Disk Diag, etc. It never gave me any problems. I also used UBCD for win, and cheked the disk, to dicover once again, that the disk supposingly has no problems.
    Any help would be appreciated.
    Thanks in advance.

    of its label Power Supply Guide
    i suspect the drives bad
    go to wd site and look for their drive tester

  • How can I disable making live shape rectangle in the first place but normal one instead in Illustrator CC?

    How can I disable making live shape rectangle in the first place but normal one instead in Illustrator CC? When I create rectangle I can't transform it by dragging and it's only the problem with rectangle, not with circle, star etc. I try show/hide edges/bounding box reset preferences and reinstall whole illustrator CC and it's the same. I can only make this right by expand this rectangle, which is shape as is turn out to rectangle by clicking object>shape>expand rectangle. But this is so frustrating. Help!:) oh, and I use OSX. My friend has the same specs and it's works. I mean she can use live shape corner transformations and changing size by draging:(

    I’ve created my own plugin (available for free for personal and commercial use) which imitates behavior of the ‘old’ Rectangle Tool. It doesn’t replace the Live Rectangle – it works completely independent!
    My Plain Rectangle Tool correctly snaps to grids/objects/points and correctly aligns to grid/points on resize. Of course it supports the SHIFT and ALT/OPTION keys, Snap to Grid and Smart Guides options. In other words it works almost 100% the same as the Rectangle Tool we know from CC (17.1), CS6 and earlier.
    The installation package (zxp) adds ‘Plain Rectangle Tool’ icon into the Ai panel (of curse you can assign your custom keyboard shortcut to it as well)
    Note: The Plain Rectangle can be easily converted into the Live one using Object > Shape > Convert to Rectangle
    Grab your copy at http://63mutants.com/subc/products/PlainRectangleTool_m01/PlainRectangleTool_m01.php Feel free to share with your friends. It’s completely free.
    I’ve also created a separate discussion https://forums.adobe.com/thread/1587587 for the Plain Rectangle Tool. If you have any comments or request please post it there. Any feedback would be greatly appreciated!
    Thanks,
    Pawel Kuc

  • I'm creating a book format in Pages. I want the page count to be 1 on the first page of chapter one after the title page, table of contents, etc.. How do I do that?

    I'm creating a book format in Pages. I want the page count to be 1 on the first page of chapter one after the title page, table of contents, etc.. How do I do that?

    That is not the issue.
    Pages/OSX does not save files with crop marks and bleeds.
    It also by default saves transparency, which is involved in a lot of Pages' better features, at a rubbishy 72 dpi resolution.
    It also makes it extremely difficult to maintain mono-color like black only text, has no spot color and makes color management opaque.
    It really is only meant for amateur publishing and printing to your desktop printer.
    A commercial printer who is willing to use and print from Pages may have better results but at the cost of considerable micro-management which defeats the point of this "cheap" solution.
    Peter

  • How to find the First block....in a multi block form

    hi
    How i can find which is the first block in a multi block form....
    ( there are n number of forms with multi blocks...so
    i need to generalise the code to find the first block in all of
    the forms)
    regards
    Kris

    If you searched in the on-line help for "First", you would find that the Get_Form_Property built-in provides two: First_Block and First_Navigation_Block.

  • I would like to fill up the following pages. If I fill up the first fields with some letters, they m

    I would like to fill up the following pages. If I fill up the first fields with some letters, they multiplay each other in several other fields, there I don't want them. Can you help me?

    You can't change that, and we can't either. It's an error in the creation of the form. ALL of the fields that "auto populate" have the same name and description, so when you fill one, the rest fill by default with the same info. You'll need to contact the author of the form and inform them of the error.

  • HT1296 I am facing a problem with my iPhone 4. I applied the first syncing with outlook 2007 by choosing the "merge" option. At the end of the process, some contacts are correctly sync, but most are only sync with the names. Numbers are lost. Any suggesti

    I am facing a problem with my iPhone 4. I applied the first syncing with outlook 2007 by choosing the "merge" option. At the end of the process, some contacts are correctly sync, but most are only sync with the names. Numbers are lost. Any suggestion?

    I would love to do this as well. All I need is my calendar appts from outlook. Right now I am using google calendar sync, but I would like to move to the cloud and away from google. I find it hard to believe there isn't an option to do this.

  • I have purchased a ringtone in the iTunes Store for my iPad, and I cannot find the download together with my music. I have received the invoice but I have no product. I am working with iOS6, if that helps. Can anybody help me?

    I have purchased a ringtone in the iTunes Store for my iPad, and I cannot find the download together with my music. I have received the invoice but I have no product. I am working with iOS6, if that helps. Can anybody help me?

    I am confused. Do you mean you found the music, not the tones, or you can't find either?
    If the former, then this is normal. You can't redownload tones from the Cloud.

Maybe you are looking for

  • Payment method E issue on F110

    Hi i tried to config the automatic vendor payment for a company and all config that i was able to get it seems corect. while running F110 and create payment proposal following error log came. If anyone face the same issue pls help i am helpless where

  • How to get the name of User NT

    I need to get the name of user NT that access to my web site (intranet), I was used the class NTSystem but this return the name of user NT of the server, but I need the current user that access to the site. Thanks a lot! yaguip

  • Problem in moving CL_BSP_WD_VALUE_NODE to CL_CRM_BOL_ENTITY

    Hi All, I am facing problem as below, ON_NEw_FOCUS method of zcontext node having entity type CL_CRM_BOL_ENTITY, but the parent having entity type CL_BSP_WD_VALUE_NODE, method do_prepare_output.     DATA: lv_entity  TYPE REF TO   if_bol_bo_property_a

  • How to launch configuration wizard in unix

    I have installed Oracle BPM Enterprise for Weblogic on a headless unix machine. I installed from a Text console as instructed in the Installation guide. However, there is no documentation on what to do next - the configuration guide does not address

  • Problem w/ Tooltips & Collapsable Panels in Safari

    Hi, I have a page that has Collapsable panels along with Tooltips that are used for a help tip in each panel. My problem is when the page loads in Safari, the contents of the bottom most Col Panels are displayed elsewhere in the page. The Col Panels