With the help of SELECT MAX (Substr (in a subquery to return specific lines

Oracle v10

Here is an example of a query and the output
SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 WHERE SAMPLEID = 'IA 0005 0166';

86907     IA 0005 0166     IA 0005     R2004:001160     2004
98158     IA 0005 0166     IA 0005     R2005:000956     2005
I try to return only the last line of data, in this case the line 2005.

I tried
SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4) FROM SEARCH PL1 
WHERE SAMPLEID = 'IA 0005 0166' AND
REQUISITION IN 
(SELECT MAX(SUBSTR(REQUISITION,2,4)) FROM SEARCH PL2 
WHERE SUBSTR(PL2.REQUISITION,2,4) = SUBSTR(PL1.REQUISITION,2,4));
But it returns no results. According to me, only missing me something simple.

TIA

You probably meant it?

SELECT ID, SAMPLEID, COMPOUNDNAME, REQUISITION, SUBSTR(REQUISITION,2,4)
FROM SEARCH PL1
WHERE SAMPLEID = 'IA 0005 0166'
AND SUBSTR(REQUISITION,2,4) = (
  SELECT MAX(SUBSTR(PL2.REQUISITION,2,4))
  FROM SEARCH PL2
  WHERE PL2.SAMPLE_ID = PL1.SAMPLE_ID
);

that could also be achieved with a single table access:

SELECT id, sampleid, compoundname, requisition, sub_req
FROM (
  SELECT id, sampleid, compoundname, requisition, substr(requisition,2,4) sub_req,
         row_number() over(order by substr(requisition,2,4) desc) rn
  FROM search PL1
  WHERE sampleid = 'IA 0005 0166'
)
WHERE rn = 1
;

Tags: Database

Similar Questions

  • Is it possible to delete a plot with the help of the mouse select the chart control?

    For example, when I use the plot to draw thousands of lines on the chart control, I want to delete some of them, but there are thousands of generated plotHandle.

    How can I get the plotHandle of the specific line on the chart control with the help of the mouse to select the option?

    If I save the information from the lines, such as the plotHandle and the coordinates on a table or list, etc, I compare information lines for the plotHandle of the specific line.
    Is it all a user-friendly way to remove a track selection on the chart control?

    I can't give you a reasonable way to solve this problem, since as you have already noted plot do not snappable plots.

    A possible warkaround would be to replace the plot of individual instructions with a PlotXY matching with 2 bays 2 points each, which correspond to the x 1, x 2, y1, y2 parameters to plot. PlotXY plots are snappable, so you can enable this procedure select the plot and remove it.

  • How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?

    How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?

    I have only:
    D: / images (where are necessary + not need files)
    -a list with only the necessary files
    -a list with new names for the files needed
    Thank you.

    Hi Pustiu,

    Thanks for posting in the Microsoft Community.

    You want to know how to select the files in a folder using a list with the files you want and after that rename only the files using another list with desired new names.

    I would have you post your query in the TechNet forums because it caters to an audience of it professionals.

    Your query will be better addressed there.

    Check out the link-

    http://social.technet.Microsoft.com/forums/en-us/w7itprogeneral/threads

    We know if you need help. We will be happy to help you. We, at tender Microsoft to excellence.

    Thank you.

  • Just installed LR6. It opens with a window that says select a catalog. There is nothing to select. With the help of windows 10

    Just installed LR6. It opens with a window that says select a catalog. There is nothing to select. With the help of windows 10

    Hey Billo,

    Could you please let me know, if you are able to see an option to "Create a new catalog" on the lower left corner of the window.

    Also, if possible, could you please attach a screenshot of the window that you see.

    Kind regards

    Tanuj

  • With the help of Photoshop CC on my MacBook Pro (bought a few months ago)... The question I have is that under the filter options, when you select made... There is no option use lighting effects... any suggestions

    With the help of Photoshop CC on my MacBook Pro (bought a few months ago)... The question I have is that under the filter options, when you select made... There is no option use lighting effects... any suggestions?

    Hello

    Please make sure that you work in 8 bits/channel and RGB mode. (Under Image > Mode > Select RGB and 8-bit per channel) lightning effects only works in this mode.

    Also in preferences > Performance > "Use Graphics Processor" must be checked.

    ~ Assani

  • Why can't I use the space bar to move rectangle selection I.E. selections. With the help of a pc in WIN7

    Why can't I use the space bar to move rectangle selection I.E. selections. With the help of a pc running WIN7. The hand icon appears, but the selection disappears. reappear when the version of the space bar

    This is a normal behavior. You need not use the space bar to move a selection.  Just have the chosen selection tools and have the cursor within the selected area.  Then just left-click and drag.

  • With the help of Adobe Acrobat Pro XI: is there a way to select existing text / change the font color of this

    With the help of Adobe Acrobat XI Pro Trial Version: is there a way to select existing text / change the font color of the text?  (there are here - but where is it to XI pro?)

    I have been using Acrobat 8 Pro & it's very simple, but I was not able to do using Pro XI!

    1. Open the PDF file
    2. Click on the Tools Menu
    3. Click the editing of content
    4. Choose text & Images

    They wanted to make it easier to get.

  • Thunderbird will only connect if stop then reopened. (With the help of Mac 10.9.4)

    With the help of Mac 10.9.4
    If I open Thunderbird, I can connect to my e-mail address and download the messages. If I select "Get Mail" once again, Thunderbird crashes and fails to connect to my emails. If I then close Thunderbird and re-open it, I'm able to immediately connect to my mail.

    It seems to have sorted itself after a few days. (Fingers crossed). Until today it worked properly. Will keep an eye on things for the next week and the report does so again.

  • ow change titles & dates of lots of pictures (like in iPhoto?) With the help of Mac 'Pages' on, 2008 aluminium MacBook running OSX El Capitan 10.11.4

    How to change titles & dates of lots of pictures (like in iPhoto?) With the help of Mac 'Pages' on, 2008 aluminium MacBook running OSX El Capitan 10.11.4

    With the help of Mac 'Pages '.

    A typing mistake?

    If it is and you mean Photos Date of Mac are modified by selecting the photos using the Image menu == > adjust the time and date of order and changes made to the metadata such as keywords, location, etc. are made by selecting the photos and find the info and registering metadata in the Info window

    These are detailed in the help topics of pictures - a good place to look for help on the Photos

    View and add information about the photos

    You can view and add information about your photos. For example, you can see the date and time a photo was taken, the information about the camera that took the photo and badges that indicate the status of the photo. You can assign titles and captions to photos, add or change the location of the photos and change the date and time for them information. You can select multiple photos in an instant and add or change information about them all at once.

    Open pictures for me

    View and add information about the photos

    To view or change information for the photos, you select one or more photos, and then open the information window.

    • Open the Info window: Double-click a photo to view it, and then click the Info button in the toolbar or press on command I.
    • Add or change information: Change the following.
      • Title: Enter a name in the title field.
      • Description: In the Description field, type a caption.
      • Favorite: Click the Favorites button to mark the photo as a favorite. Click the button again to deselect.
      • Keywords: Enter the keywords in the keywords field. When you type, Photos suggest keywords that you have used before. Press enter when you have finished a keyword. To remove a keyword, select it and press DELETE.
      • Faces: Click on and type a name to identify a face. Click on several times, and then drag the identifier of the face different faces to identify many faces in a photo.
      • Location: Enter a location in the location field. When you type, Photos suggest places you can choose. To change a location, you can search a different location or change the location by dragging a PIN on the map. To remove location information, delete it or choose Image > location, then choose Remove location or back to the original location. You cannot assign a location if your computer is not connected to the Internet.

    Show titles, other metadata and badges

    Change the date and time of photo

    You can change the date and time associated with a picture. You can do this if you are traveling to a location in another time zone, and your camera affect your dates photos and periods that are correct for your House, but not the place you visited.

    1. Select the photos you want to edit.
    2. Choose Image > adjust Date and time.
    3. Enter the date and time you want in the modified field.
    4. Click a time zone on the map, if necessary.
    5. Click on adjust.
  • Windows 7 will not be activated. With the help of a legitimate license key.

    Windows 7 will not activate... With the help of a legitimate license key.

    Have you tried to activate by phone?

    Activate Windows 7 manually:
    1. click on start and in the search for box type: slui.exe 4

    2. press enter on your keyboard

    3. Select your country.
    4. Select the telephone activation option and brace yourself for a real person.

    Please run the Microsoft Genuine Diagnostics Tool then copy and paste the results into an answer here for further analysis:
    http://go.Microsoft.com/fwlink/?LinkId=52012

    Releasing it's easy: with Windows | ActiveWin | Laptops | Microsoft MVP

  • With the help of JavaScript condition in the dynamic action of JQuery selector

    Hi guys,.

    I have a Setup master detail on a page.

    The detail section, I have a tabular presentation.  One of the fields is a selection list.  The first record in the select contains the value * not * that has a value of primary key for the 1.  I have a distinct region with a simple text field where the user can insert a value into the table if the value does not exist.

    I want than the region of text element to only appear if the value * not listed * is selected.

    I managed to make it work when the value is selected with the help of dynamic action with a bit of JQuery and JavaScript by setting the ID on the selection list to 'create' and have the following in JavaScript $(this.triggeringElement) .val ()! = 1 in the JavaScript for dynamic action condition shows it or hides the region of 'create' and that works well.

    However, if the secondary table is empty before the detail records were created (nothing selected in triggering jQuery Selector) the region of create is displayed when I don't want it.

    I guess I need some sort of NVL in JavaScript condition?

    I use APEX v4.2.

    Any advice would be appreciated.

    Chris

    Cashy wrote:

    I have a Setup master detail on a page.

    The detail section, I have a tabular presentation.  One of the fields is a selection list.  The first record in the select contains the value * not * that has a value of primary key for the 1.  I have a distinct region with a simple text field where the user can insert a value into the table if the value does not exist.

    I want than the region of text element to only appear if the value * not listed * is selected.

    I managed to make it work when the value is selected with the help of dynamic action with a bit of JQuery and JavaScript by setting the ID on the selection list to 'create' and have the following in JavaScript $(this.triggeringElement) .val ()! = 1 in the JavaScript for dynamic action condition shows it or hides the region of 'create' and that works well.

    However, if the secondary table is empty before the detail records were created (nothing selected in triggering jQuery Selector) the region of create is displayed when I don't want it.

    I guess I need some sort of NVL in JavaScript condition?

    I use APEX v4.2.

    Simple solution is to hide the region containing the element of text by default, using the style = "" view: no ' in the property of the attributes of the area in the region. " It will be always hidden when the page initially, but its visibility will be controlled by the DA subsequently.

  • With the help of PSE v14 when PSE v10 is still in my iMac with iPhoto and when I click on a photo and click on change, he wants to keep opening PSE v10.  I just installed a temporary version of PSE v14 and would really like to use to see want I can do.

    With the help of PSE v14 when PSE v10 is still in my iMac with iPhoto and when I click on a photo and click on change, he wants to keep opening PSE v10.  I just installed a temporary version of PSE v14 and would really like to use to see want I can do.

    You open iPhoto or organizer? If the latter; Check your configuration. During your installation, make sure you select the application, and not an alias (shortcut). Go to this link.

    PSE14 as an external editor

  • I have customized a widget and want to reuse on another page. How save, copy or reproduce them? With the help of the iMac and Muse 2015

    I have customized a widget and want to reuse on another page. How save, copy or reproduce them? With the help of the iMac and Muse 2015

    You can just copy/paste the enchilada itself on another page, pretty easy!

    If you want to reuse more often, you can open the library or libraries CC , to store and later hanging out once again. Note: for the creation of an article in the 'old' library, you must select the element on the page and click on the new icon in the " library " window To create an element of CC libraries , you can simply drag something in and out of the window libraries CC .

  • Problem with the help of oraext: query-database in the transformation (XSLT 2.0)

    Hello!
    I m facing a problem with the help of oraext: query-database.

    In my transformation im try the following (Simplified):
    <xsl:template match="*">
      <xsl:variable sqlQuery="select ....."/>
      <xsl:variable name="storeSec" select="oraext:query-database($sqlQuery,true(),true(),'jdbc/xref')/>               
        <xsl:choose>
         <xsl:when test="string-length($storeSec/ROWSET/ROW[1]/STORE_PART_SECTION) > 0">
              <xsl:value-of select="$storeSec/ROWSET/ROW[1]/STORE_PART_SECTION"/>
         </xsl:when>
           <xsl:otherwise>
                <xsl:value-of select"some other val"/>
           </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    {code}
    
    This always results in +some+ +other+ +val+ !!
    I´v checked the output from oraext:query-database by using getcontentAsString and if I instead test putting the expected output from oraext:queryDatabase in my variable it gives me A100 which is what i expected.
    
    {code}
    <xsl:template match="*">
      <xsl:variable sqlQuery=select ....."/>
      <xsl:variable name="storeSec">
        <ROWSET>
         <ROW num="1">
           <STORE_PART_SECTION>A100</STORE_PART_SECTION>
         </ROW>
         <ROW num="2">
           <STORE_PART_SECTION>XXm</STORE_PART_SECTION>
         </ROW>
        </ROWSET>
      </xsl:variable>               
        <xsl:choose>
         <xsl:when test="string-length($storeSec/ROWSET/ROW[1]/STORE_PART_SECTION) > 0">
              <xsl:value-of select="$storeSec/ROWSET/ROW[1]/STORE_PART_SECTION"/>
         </xsl:when>
           <xsl:otherwise>
                <xsl:value-of select"some other val"/>
           </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    How to get the correct value when you use oraext:query - database?

    How should you exit? Several item ID with each having a value of the result set?
    If Yes, then you can try following:

     
                        
                            
                        
                             
                                  
                             
                        
                            
    
  • Insert the record of one table to another with the help of the cursor

    Help, please!

    the tables are - 1. countries (country_id pk, country_name, region_id)
    2A (country_id, country_name, region_id)
    table data are
    1 to 1
    2 b 2
    3 C 3
    NULL d 4
    5 e 5
    6 f 6
    7 g 7
    -----------------------
    Insert the record in the table a country table with the help of the cursor, insert all the non-null records.
    This procedure does not correct result
    -----------------------

    create or replace
    Amit procedure as
    cursor c1 is select * from a;
    RW a % rowtype;
    Start
    Open c1;
    Fetch c1 into rw.
    While (C1% found)
    loop
    insert into countries values (rw.country_id, rw.country_name, rw.region_id);
    commit;
    Fetch c1 into rw.
    If rw.country_id is null then
    Fetch c1 into rw.
    end if;
    end loop;
    Close c1;
    exception
    while others then
    dbms_output.put_line ('exception = name ' |) RW.country_name);
    end;

    You don't need cursor at all;

    create or replace procedure amit as
    
    begin
      insert into countries (Country_ID, Country_Name, Region_ID)
      (select a.Country_ID
             ,a.Country_Name
             ,a.Region_ID
       from a
      );
    
      dbms_output.put_line('Rows inserted : ' || sql%rowcount);
    
      commit;
    
    end;
    /
    

Maybe you are looking for