Need help updating records from a subset yielded by a subquery.

Hi, retired, hobby coder needing (further) help in transact-sql scripting with a view to creating a stored procedure within a Sequel DB.  For the purposes of this investigation I have a table with 23 records.   I am trying to update a specific
field for 10 of the records based on the (TOP 10) records selected from a sub query where I select the TOP 20 records based upon different field.
I select my desired 10 records (TOP 10) from a sup query selecting the TOP 20 based upon the date field (latest 20) for a specific user (GID) as follows:
I then attempt to update only these 10 records as follows:
As you can see it updated all 23 rows in the table, not just the 10 I yielded by the underlying query.
In reviewing the documentation it appeared that referencing the Scores_id column and using the 'IN' keyword would work, i.e., UPDATE Scores WHERE Score_id IN (SELECT TOP 10* ..... would be appropriate but I got the an error message, 'Only one expression
can be specified in the select list when the subquery is not introduced with EXISTS.'
Can someone assist me with the proper syntax for this script?  Additionally, since there are limitations on the number of variables which can be used any advice on how to structure a stored procedure where the GID is the initial variable and Score_id
the second would be appreciated also.
Regards,
Minuend

The query you have written will always update all or no rows in the table, since it says
UPDATE Scores
SET    ...
WHERE  EXISTS (...)
The EXISTS clause is, logically, evaluated for each row. Normally, when you use EXISTS you correlated the subquery with the surrounding query, so that the values the subquery works with are different for each row. But your subquery is uncorrelated, and will
return the same value, TRUE or FALSE, for each row.
IN can certainly work, but then you cannot have "SELECT TOP 10 *", but you need to have "SELECT TOP Score_id", since when you use IN, the subquery must be a single-column query.
Another alternative, which is somewhat difficult to digest the first you see it, but which is more efficient, and more concise, once you have learn it, is to work directly from the query you have:
  WITH CTE AS (
     SELECT TOP 10 *
      FROM (SELECT TOP 20...
 UPDATE CTE
 SET    Used = '*'
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Need help: updating records from a node to another node.

    Hi Gurus,
    I guess most of you would be laughing at me but I'll not from Java background but.
    scenario:
    I have a node (eg. Node A) containing some records, say...with keys A,B,C,D,E.
    I also having anothe node (eg Node B) containing the update records of some of the Keys, eg. A,D,E
    How do I update node A with the updated values of node B.
    a ABAP representation would be:
    LOOP AT NODE_B.
      LOOP AT NODE_A.
        IF NODE_A-KEY = NODE_B-KEY.
          MOVE-CORRESPONDING NODE_B to NODE_A.
          MODIFY NODE_A.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
    thanks.

    Hi Jansen,
    Are you using model node or value? If it is model node you need store in Node B just reference to model class from Node B. If it is value node then you can store keys of elements from Node A moved to Node B in some java Map implementation.
    Best regards, Maksim Rashchynski.

  • Need help Updating Records in a Report Region

    We have created some javascript to check a drop down used in a report region.
    This is the way the report is supposed to work:
    The first time the user comes to this screen he will go down the list and select a value of '1' or '2' for col2.
    When col2 drop down has a value of 1 then we want to disable col3 and col4.
    Then the user will click on the Submit button.
    When he clicks on the Submit button then we want to set col4 to have a value of sysdate in the database table for any record where col2 had a value of 1.
    The next time the user comes to this screen he will select values for col3 and col4 of the records that col2 had a value of 2 (meaning col3 and col4 are enabled)
    This works fine if there is only one record in the report region.
    The problem is when we have more than one record.
    for example:
    Say we have two records...
    for record1 the user selects '1' for col2 and for record2 the user selects '2' for col2.
    When the user clicks on the Submit button col3 and col4 get disabled and col4 gets set to sysdate for record1, while col3 and col4 remain available but empty (because the user has not made a selection for these columns at this point) for record2.
    When the user comes back to this screen he now selects a value for col3 and picks a date for col4 for record2. When he clicks on the Submit button the value for col3 and the date entered in col4 for record2 should get updated in the database table and it is but the col3 value and the col4 date is being inverted with record1's data for some reason.
    Can you please tell me how to fix this?
    This is what the user has selected on the screen:
    (COL2) (COL3) (COL4)
    Requested? Granted? Response Date
    Record1 NO - 13-APR-09
    Record2 YES YES 20-APR-09
    After the user clicks on the Submit button this is how the screen displays it back:
    (COL2) (COL3) (COL4)
    Requested? Granted? Response Date
    Record1 NO YES 20-APR-09
    Record2 YES N/A 13-APR-09
    I am including the code from my update staement below:
    DECLARE
    A_ID NUMBER;
    requested NUMBER;
    grnted NUMBER;
    respdate DATE;
    f01 = AID ID
    f02 = REQUESTED YES OR NO
    F03 = GRANTED YES OR NO
    F04 = RESPONSE DATE
    BEGIN
    FOR i IN 1..HTMLDB_APPLICATION.G_F01.COUNT LOOP
    BEGIN
    A_ID      := HTMLDB_APPLICATION.G_F01(i); -- this is hidden
    requested := HTMLDB_APPLICATION.G_F02(i); -- (YES or NO)
    grnted := HTMLDB_APPLICATION.G_F03(i); -- (YES or NO)
    respdate := to_date(HTMLDB_APPLICATION.G_F04(i),'MM/DD/YYYY');
    EXCEPTION
    WHEN OTHERS THEN
    A_ID      := HTMLDB_APPLICATION.G_F01(i); -- this is hidden
    requested := HTMLDB_APPLICATION.G_F02(i); -- (YES or NO)
    grnted := 3; -- (YES or NO)
    respdate := sysdate;
    END;
    UPDATE TBL_AIT
    SET b_requested_id = requested,
    b_granted_id = grnted,
    b_response_date = respdate
    WHERE ait_id = A_ID;
    END LOOP;
    END;

    Hi,
    Any disabled items are not submitted with the page - therefore, your f03 and f04 collections would be one value short. This is a browser feature rather than an Apex feature.
    You can get around this by enabling all items before the submit takes place. Have a look at: Re: A better method of handling tabular forms with variable column type? This is for disabling items mainly, but includes an enableItems() javascript function that should help you.
    Andy

  • HT1267 i need help updating without wifi hook up. I was told I could do through my "itunes"

    I need help updating without wifi hook up. I was told I could do it through my "itunes"

    after selecting restore from backup, you should see a screen asking you wich backup (on the computer)

  • HT1338 need help updating to snow leopard

    need help updating to snow leopard

    Hi Billy,
    First you need to research all the problems people are having with the higher OSX versions, & make sure you have a bootable clone of what you have just in case.
    then you must get 10.6 if they still have it, install it & update to 10.6.8 so you have the App Store to buy & download the huge 10.8 Installer.
    Snow Leopard/10.6.x Requirements...
    General requirements
       * Mac computer with an Intel processor
        * 1GB of memory (I say 4GB at least, more if you can afford it)
        * 5GB of available disk space (I say 30GB at least)
        * DVD drive for installation
        * Some features require a compatible Internet service provider; fees may apply.
        * Some features require Apple’s MobileMe service; fees and terms apply.
    Which apps work with Mac OS X 10.6?...
    http://snowleopard.wikidot.com/
    It's been pulled from the online store & Apple Stores, so you have to call Apple to buy it, last I heard.
    Call Apple Sales...in the US: 1-800-MY-APPLE. Or Support... 1-800-275-2273
    Other countries...
    http://support.apple.com/kb/HE57

  • Getting the un updated records from receiver JDBC

    Hi Friends,
         I am doing the Proxy - jdbc integration. Consider my proxy sends 10 records to JDBC to update. Consider bcoz of some reason the jdbc updates only 8 records i need to get the 2 records back to Proxy which is not updated in the DB.
    Should i need to use the Proxy and JDBC channel as syn or seperate integration should be built. I have seen some documents, that we can get the count of the updated records from jdbc receiver, but i dont need the count i need the record which is not been updated.
    How can i do it. please give ur inputs.
    thanks
    Prem

    Unless  you are using SP on JDBC side and explicitly build a record set to send back the data it might not be possible. I am not sure if a custom record set could be returned in JDBC sync receive adapter. You can realize this by updating some other table on JDBC side and then polling that table to update ecc back.
    VJ

  • I need help removing CS3 from Windows 7 so I can reinstall

    I need help removing CS3 from Windows 7 so I can reinstall

    Before trying to remove try re-installing CS3 right on top of the current install.  Often re-installing Photoshop on top of itself fixes the install.  If it does be sure to apply the cs3 updates.
    Download Adobe CS4 and CS3 Free Trials Here (incl. After Effects) | ProDesignTools
    your product key can be retrieved from here https://www.adobe.com/account/my-products-services.html
    use these links for the updates.
    Adobe - Photoshop : For Macintosh
    Adobe - Photoshop : For Windows

  • HT1237 I have a iMac8,1.  Am needing to update firmware from 10.5.8 to 10.6 or later.

    I have an iMac 8,1.  Am needing to update firmware from 10.5.8 to at least 10.6 for new printer.  Help.

    I'm afraid what you've asked about is not firmware. Rather it's OS X - the operating system.
    Upgrading to Snow Leopard
    You can purchase Snow Leopard through the Apple Store: Mac OS X 10.6 Snow Leopard - Apple Store (U.S.). The price is $19.99 plus tax. You will be sent physical media by mail after placing your order.
    After you install Snow Leopard you will have to download and install the Mac OS X 10.6.8 Update Combo v1.1 to update Snow Leopard to 10.6.8 and give you access to the App Store. Access to the App Store enables you to download Mavericks if your computer meets the requirements.
         Snow Leopard General Requirements
           1. Mac computer with an Intel processor
           2. 1GB of memory
           3. 5GB of available disk space
           4. DVD drive for installation
           5. Some features require a compatible Internet service provider;
               fees may apply.
           6. Some features require Apple’s iCloud services; fees and
               terms apply.
    Upgrading from Snow Leopard to Lion or Mavericks
    To upgrade to Mavericks you must have Snow Leopard 10.6.8, Lion, or Mountain Lion installed. Purchase and download Mavericks (Free) from the App Store. Sign in using your Apple ID. The file is quite large, over 5 GBs, so allow some time to download. It would be preferable to use Ethernet because it is nearly four times faster than wireless.
         OS X Mavericks- System Requirements
           Macs that can be upgraded to OS X Mavericks
             1. iMac (Mid 2007 or newer) — Model Identifier 7,1 or later
             2. MacBook (Late 2008 Aluminum, or Early 2009 or newer) —
                 Model Identifier 5,1 or later
             3. MacBook Pro (Mid/Late 2007 or newer) — Model Identifier 3,1 or later
             4. MacBook Air (Late 2008 or newer) — Model Identifier 2,1 or later
             5. Mac mini (Early 2009 or newer) — Model Identifier 3,1 or later
             6. Mac Pro (Early 2008 or newer) — Model Identifier 3,1 or later
             7. Xserve (Early 2009) — Model Identifier 3,1 or later
    To find the model identifier open System Profiler in the Utilities folder. It's displayed in the panel on the right.
    Are my applications compatible?
             See App Compatibility Table — RoaringApps.
    Upgrading to Lion
    If your computer does not meet the requirements to install Mavericks, it may still meet the requirements to install Lion.
    You can purchase Lion at the Online Apple Store. The cost is $19.99 (as it was before) plus tax.  It's a download. You will get an email containing a redemption code that you then use at the Mac App Store to download Lion. Save a copy of that installer to your Downloads folder because the installer deletes itself at the end of the installation.
         Lion System Requirements
           1. Mac computer with an Intel Core 2 Duo, Core i3, Core i5, Core i7,
               or Xeon processor
           2. 2GB of memory
           3. OS X v10.6.6 or later (v10.6.8 recommended)
           4. 7GB of available space
           5. Some features require an Apple ID; terms apply.

  • How to update Records from Internal table to u2018Zu2019 table?

    Hi Friends,
    How to update Records from Internal table to u2018Zu2019 table.
    I have records in Internal table , that records want to update on u2018Zmarau2019 Table.
    ( my internal table & u2018 Zu2019 table structures are same.)
    Thanking you.
    Regards,
    Subash

    Hi,
    loop at internal table.
    modify <Z- table > from values < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    endloop.
    or
    UPDATE <Z- table > from table < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    Prabhudas

  • TS1389 I need help removing UAC from itunes..

    I need help removing UAC from itunes so it will not allow me to open itunes. Everything I have read from other comments that you shouldn't turn off your user account control. I just to be able to open itunes. Can anyone help me with this problem?? Greg, ogrady612@yahoo,com

    I had this problem too but you do not need UAC to be turned on.
    Click on start and search for 'uac' in the search box at the bottom and click on 'Change User Account Control Settings' when it comes up. Move the slider to the bottom when the window appears and save the changes and your done!
    It's worked for me and my uac has been off for months without causing me any problems!
    Hope this helped

  • Need help coping project from one computer to another.

    I need help coping project from one computer to another.  I loaded all video on computer 1, copied events and project folder to computer 2.  I was told I only needed to copy the project folder back to computer 1 since the events folder is already there.   I copied project folder back to computer 1 but the files wont open.  I dont have computer 2 available. 
    Please help!!!

    Hi
    No that's not the way to do it - iMovie gets confused and in some cases the problems might be un-repairable.
    You've got several problems
    • iMovie'08 - CAN NOT MOVE PROJCTS - You NEED iMovie'09 or iMovie'11 - I see no other working solution
    • Never MOVE or alter any folder named
    iMovie Projects - or -
    iMovie Events
    on DeskTop/Finder - This might be very harmful
    • Moving (Projects) and Events - HAS TO be done within the iMovie Application.
    You've got an Evets window and here You can view Your Events in two ways - Yearly - or - Yearly per Hard disk
    Here You can move within this "window" to another location
    • Projects - NO they do not contain Your full movie - only a document on howto use the material in Event folder
    and there might be worse if You added Photos from iPhoto and Audio from iTunes/Garageband - then You have
    to get this over to the second Mac too, to be able to continue editing.
    So to move Your projects to another Mac You need
    • iMovie'09 or 11
    • an external hard disk -
    MUST BE Mac OS Extended formatted - as UNIX/DOS/FAT32/Mac OS Exchange will not work for VIDEO
    Should be a FireWire one - as UBS/UBS2 performs badly when used for video
    • Then move/copy over within Project resp Events window in iMovie Application
    Hopefully I've been not to confusing or badly structured to be followed.
    Yours Bengt W

  • Deleting/Updating records from an object table in PL/SQL

    Hello All,
    VER:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE     11.2.0.3.0     Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    I have created an object and inserted records in it. Is there any way we can delete/update records from it. I do not want to delete based on iteration like delete.collection but I would like to know if we can delete directly from obj like delete from table...
    CREATE OR REPLACE TYPE test_type AS OBJECT
    col1 number,
    col2 varchar2(100)
    CREATE OR REPLACE TYPE tab_type is table of test_type;
    DECLARE
    test_tab tab_type;
    l_cnt NUMBER;
    BEGIN
    select test_type(col1,col2) bulk collect
    into test_tab from (select 1 as col1,'test1' as col2 from dual
                        union all
                        select 2,'test2' from dual);
    IF test_tab.count>0
    THEN
    DELETE FROM TABLE(CAST(test_tab as tab_type)) a
    where a.col1=1;
    END IF;
    l_cnt := test_tab.count;
    END;Thx
    Shank.

    SB,
    I have a scenario wherein I insert few records into a collection table. I'm gonna filter few records from collection table based on the filter.
    I want to delete the records that didn't match the filter. Right now, I'm inserting the records into a physical table and deleting from there. I do no want to use a physical table. Trying to avoid it.
    Would like to delete from collection itself.
    DELETE FROM TABLE(CAST(lv_attr_filter_tab as EDMS_CSPP_DISC_REQ_TAB_TYPE))
                                 WHERE NOT EXISTS (SELECT 1
                                       FROM edms_disc_lines_stg edls
                                       WHERE edls.req_id = edrg.request_id
                                          AND edls.disc_line_id = edrg.discount_id
                                          AND UPPER(edls.disc_status) IN ('ACTIVE');

  • HT4623 I need help updated my iphone, please help

    My need help updating my iphone, I went through the steps to update and now it shows connect to itunes, what do I need to do next.?

    Rajan Gupta wrote:
    ...it is continuously showing an error.
    See here  >  http://support.apple.com/kb/TS3424
    Also see this discussion.
    https://discussions.apple.com/message/21189708

  • TA48312 need to update system from 10.4.11 to 10.5.7 for the airport express to work

    need to update system from 10.4.11 to 10.5.7 to get airport express to work, is this possible?

    Yes. Since you're using a MacBook, purchase Mac OS X 10.6 on DVD.
    (64416)

  • I have Iconia Tab A500, running 3.0, need help updating using microsd card, got Acer update download

    I have Iconia Tab A500 running 3.0, need help updating, I downloaded all updaes list in the acer supprt, all versions, 3.0, 3.1, 3.2, and 4.something, I read on the acer support somewhere I can use a microsd card to update my device, because acer no longer provides automatically, when i try it says "poor network connection, move to anthoer location.", Do I need to update all the listed updates, or can i only update, using the 4. 0? to get the last known update. I also downloaded, "Documents, Apllications, Drivers, Patches, and O.S..... How do i intsall all these updates, I think am running the very lowest version available, Please Help me... Thank you in advance.

    the update listed on the acer website, that mentions the a500 update is 'kernal source code (for Android 4.0 Ice Cream Sandwich) it's 96.7MB's released 2012/05/08' is that the right one i need? There is also a list of 3 O.S updates, released in 2014/09/05, 391.5MB's, 394.3MB's, and 391.5MB's large, what are those updates, I clicked the model and followed the directions that the acer website asks, and i ended with a list of update released in 2014/09/05, and a Document update released in 2014/12/17, 112.7KB's large,  list of updates reased in 2014/.... and in the Android 4.0 culumn, there is an update that says O.S update released in 2014/09/05, 434.2MB's large, and a Patch Update, that was released in 2013/03/21, what are these updates? listedin the aver website... http://www.acer.ca/ac/en/CA/content/drivers 

Maybe you are looking for

  • JSF / Switch between HTTP and HTTPS

    Hello! I want to switch between HTTP and HTTPS using JSF. Under Apache Struts framework I can use struts extension "sslext.jar" to configure switching between http and https in one web application. e.g. Login-jsp should be secured, all other jsp's sh

  • Is there a way to use an iphone 4 as a wired USB web camera?

    I've researched alot of apps that will allow the iphone to be used as a webcam, but they all seem to be wireless... is there any way to do this through a USB connection? (I hope to make stopmotion animition using dragonframe with my iphone as an exte

  • "Itunes Cannot connect to I Tunes Store"

    When I try to go to I Tunes store a message appears telling me to make sure my network connection is active and try again. I am connected to the internet so I'm not sure why im getting this error? My laptop is new and has Windows Vista..Please help!

  • CFdocument not rendering

    After converting to CF8 the cfdocument tag does not work well. I only get the first cflayoutarea. I've researched it and no one seems to have had this particular problem. I have a normal cfm page with a checkbox to create a PDF from it. The page I di

  • My email has stopped allowing me to log in; it is telling me the password is incorrect, even though I am putting in the correct password.  Help!

    Today, while I was using my email, it suddenly stopped working and told me that my email required a password.  When I went into settings to put in a password, the phone told me it was incorrect.  When I got home to try and figure out what was going o