Can I use Order By in a delete query

Hey everybody,
I have an issue to delete old records for "my recent projects' based on the customization (5 prjs in a shot like that.)
I am just firing a sub query to do this
like.... DELETE FROM TABLE_NAME1 WHERE ID IN (SELECT ID FROM TABLE_NAME1 WHERE ROWNUM<=5 ORDER BY UPDATED_ON DESC)
But in this case I am getting "Right paranthesis missing" error......
Please help me anyboddy......
Thanks in advance..........

First, it doesn't make sense to put an ORDER BY there. You're asking for an arbitrary 5 rows and then sorting those 5 rows, but the order of results in an IN clause is irrelevant.
Potentially, you meant something like
DELETE FROM table_name
WHERE id IN (
    SELECT id
        FROM (SELECT * FROM table_name ORDER BY updated_on DESC)
      WHERE rownum <= 5
  );Justin
I see intss beat me to the punch.
Message was edited by:
Justin Cave

Similar Messages

  • How can i use Order by inside a sub query in Oracle

    Hi!,
    Please help me, it's an urgent... how can i use Order by clause
    SELECT SalesProductKeyID,ActualUnitPrice,BillDateKeyID,ProductKeyID
    ,Qty,Profit,DD.dDate
    , (SELECT nvl(S.Qty,0) FROM Stock S , DateDimension DD1
    WHERE S.DateKeyID = DD1.DateKeyID AND
    S.ProductKeyID = SF.ProductKeyID AND
    DD1.dDate <= DD.dDate and rownum=1
    ORDER BY DD1.dDate DESC*) as StockQty
    , (SELECT nvl(SUM(Qty),0) from salesfact SF2,DATEDIMENSION DD2
    WHERE SF2.BillDateKeyID=DD2.DatekeyID AND SF2.ProductKeyID=SF.ProductKeyid
    AND DD2.dDate > DD.dDate
    AND DD2.dDATE=DD.dDate
    ) as TotalQtySold
    FROM SalesFact SF INNER JOIN DATEDIMENSION DD
    ON SF.billdatekeyid =DD.Datekeyid
    WHERE
    IsProfitCalculated = 1 AND
    IsSalesFactSuppPopulated =0 AND
    Qty > 0;
    kindly help
    Thank you.

    Actually I'm converting Procedures from SQL Server to Oracle.
    Actual Stored Procedure in SQL Server is as follows.
    SELECT --top 10000 
    SalesProductKeyID,ActualUnitPrice,BillDateKeyID,ProductKeyID
    ,Qty,Profit,DD.Date
    , (SELECT TOP 1 ISNULL(S.Qty,0) FROM dbo.Stock S , dbo.DateDimension DD1
    WHERE S.DateKeyID = DD1.DateKeyID AND
    S.ProductKeyID = SF.ProductKeyID AND
    DD1.Date <= DD.Date
    ORDER BY DD1.Date DESC) as StockQty
    , (SELECT ISNULL(SUM(Qty),0) from salesfact SF2,DATEDIMENSION DD2
    WHERE SF2.BillDateKeyID=DD2.DatekeyID AND SF2.ProductKeyID=SF.ProductKeyid
    AND DD2.Date > DD.Date
    AND DD2.DATE=DD.Date
    ) as TotalQtySold
    --INTO TEMP_Salesfact          
    FROM dbo.SalesFact SF INNER JOIN DATEDIMENSION DD
    ON SF.billdatekeyid =DD.Datekeyid
    WHERE
    IsProfitCalculated = 1 AND
    IsSalesFactSuppPopulated =0 AND
    Qty > 0

  • How can I use a new computer without deleting everything on iPod?

    Hey Guys
    I need a bit of help.
    My old computer died, it was running Windows XP. I've got myself a new computer running Windows 7.
    I have a copy of my iTunes folders from my old computer (taken 2 days before it died)
    How can I use a new computer without deleting everything on iPod touch?
    I've imported all the folders (music, apps etc) into the new computer's iTunes, but when I sync my iPod
    I receive a window asking if i want to sync i need to erase and replace with the iTunes library on the computer.
    I particularly don't want to do this.
    My wife also uses my iTunes for her iPhone.
    Any help would be appreciated. Thank you

    Make a backup of the iPod by connecting the iPod to the computer and right clicking on the iPod under Devices in iTunes and selecting Backup. Then restore the iPod from that backup and sync as necessary.

  • Services that can't use Order on Behalf

    Services that can't use Order on Behalf
    Hi - does anyone know if there is a way to exclude specific services from using Order on Behalf?

    Hi Wendy,
    This use case can be handled by creating an AFC Conditional Rule that is triggered with the onLoad and onSubmit events.  Please see below for the sample conditional rule:
    Type:

  • In Oracle, Can i use if exits clause in a query?

    In Oracle, Can i use if exits clause in a query?
    For example, "Drop table if exists tablename"
    Is the above command valid in oracle?
    If not then is there any equivalent for if exists clause?

    Here is the SP code code that might help you to Drop a table if it exisit, whith out throwing an error if the table is not present.
    create or replace PROCEDURE DROP_TABLE(TabName in Varchar2)
    IS
    temp number:=0;
    tes VARCHAR2 (200) := TabName;
    drp_stmt VARCHAR2 (200):=null;
    BEGIN
    select count(*) into temp from user_tables where TABLE_NAME = tes ;
    if temp =1 then
    drp_stmt := 'Drop Table '||tes;
    EXECUTE IMMEDIATE drp_stmt;
    end if;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    END DROP_TABLE;
    Call this SP in your Scripts by : CALL DROP_TABLE ('<Table Name>')
    Hope this Helps!
    Regards,
    Kaarthiik

  • Can I use a OID rule for a Query SQL Lov of BIP?

    Hi. Can I use OID data (rules) for a query sql lov in BIP? Ex. filters users/store.
    Thank you.
    R.

    Hi,
    I didn't look at the example, but if you want to secure your application then you should use container managed security. Read this .
    Anyway, you could add this before return "good"; in your login_action()
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("username", user);Then, you can access this from anywhere in the application by using #{sessionScope.username}.
    Pedja

  • Using order by in the select query

    Hi All,
    I have query in which I need the latest record. To get the latest record, I can
    1) Select all entries into an internal table and sort them descending and get the first one
    2) Select all entries into an internal table and order by in the select statement itself.
    Then read the first one.
    Which approach should be better as for as the performance is concern.
    The query is on MKPF table and I have the material document number. I need the latest entry.
    Regards,
    Shahu

    Hi,
    The first one would be better.At the most we should not use order by in select statement bcoz it directly sorts the data according to that in database itself reverting performance issues.
    Otherwise you can use select max* if records are less.
    Reward points if helpful.
    Thanks,
    Ponraj.s.

  • How Can I use a Variable  in Data Controls query. Frank Kindly check...

    Hii,
    I am using JDeveloper 11g ADF BC.
    My Requirement is that I hv a login screen which is taken from [http://blogs.oracle.com/shay/simpleJSFDBlogin.zip].
    I hv attached BC in this application. I want to use the login usercode in the next pages after login screen. Next screen contains 3 list items which will be populating based on the user. So I created &lt;af:selectOneChoice&gt; using the BC( Just drag & dropped the column into the page from the data controls). But in the data control i want to use this usercode for passing the condition. Now Data is coming without any condition.
    So How can I use the usercode in the Data controls query.
    When I tried to display the usercode in the next page it is showing by binding the value. its code is follows
    &lt;af:outputText value="#{backing_getUser.uid}"
    The program for checking the username & Password is follows.
    package login.backing;
    import oracle.adf.view.rich.component.rich.RichDocument;
    import oracle.adf.view.rich.component.rich.RichForm;
    import oracle.adf.view.rich.component.rich.input.RichInputText;
    import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
    import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
    import java.sql.*;
    import java.util.List;
    import java.util.Map;
    import oracle.adf.view.rich.component.rich.output.RichMessage;
    import oracle.jdbc.OracleDriver;
    public class GetUser {
    private RichInputText uid;
    private RichInputText pid;
    private RichCommandButton commandButton1;
    private RichInputText inputText1;
    private RichInputText inputText2;
    public void setUid(RichInputText inputText1) {
    this.uid = inputText1;
    public void setPid(RichInputText inputText2) {
    this.pid = inputText2;
    public RichInputText getUid() {
    return uid;
    public RichInputText getPid() {
    return pid;
    public void setCommandButton1(RichCommandButton commandButton1) {
    this.commandButton1 = commandButton1;
    public RichCommandButton getCommandButton1() {
    return commandButton1;
    public String login_action() {
    // Add event code here...
    String user = this.getUid().getValue().toString();
    // String pass = inputText2.getValue().toString();
    String pid = this.getPid().getValue().toString();
    Connection conn;
    conn = getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery ("SELECT usercode FROM guser where usercode = '"+user.toUpperCase()+"' and pwd=F_TEST('"+pid.toUpperCase()+"')");
    if (rset.next()) {
    conn.close();
    return "good";
    conn.close();
    } catch (SQLException e) {
    System.out.println(e);
    return "bad";
    public static Connection getConnection() throws SQLException {
    String username = "ACCTS";
    String password = "ACCTS";
    String thinConn = "jdbc:oracle:thin:@SERVER1:1521:G5PS";
    DriverManager.registerDriver(new OracleDriver());
    Connection conn =
    DriverManager.getConnection(thinConn, username, password);
    conn.setAutoCommit(false);
    return conn;
    public void setInputText1(RichInputText inputText1) {
    this.inputText1 = inputText1;
    public RichInputText getInputText1() {
    return inputText1;
    public void setInputText2(RichInputText inputText2) {
    this.inputText2 = inputText2;
    public RichInputText getInputText2() {
    return inputText2;
    -----

    Hi,
    I didn't look at the example, but if you want to secure your application then you should use container managed security. Read this .
    Anyway, you could add this before return "good"; in your login_action()
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("username", user);Then, you can access this from anywhere in the application by using #{sessionScope.username}.
    Pedja

  • Can we use global structure while designing a query on  a multiprovider

    hai friends,
                     If i build a multiprovider on cubes for which the query design  on those cubes contains global sturctures ,
    Can i use those global structures while designing a query on a multiprovider (which contains those cubes)

    Hi Vamsi,
    The structure from the base cubes will not automatically be available for the queries created on the multiprovider. The only way to get the structure there is to copy a query from the base cube to the multiprovider. You can use transaction RSZC to do this.
    Hope this helps...

  • Can I use multiline SQL commands in a query (within a component)?

    I would like to modify the following query:
    <td>ItranslationString</td>
         <td>
         INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile) VALUES (?, ?, ?, 'N', ?)
         </td>
         <td>daKeyField varchar
         daLanguageField varchar
         daTranslationField varchar
         StringTranslationFilename varchar
         </td>
    so that the daSourceFile a) is selected from another record, if it exists b) uses the constant, if not.
    In SQL Command the commands (without placeholders) look:
    declare c integer;
    res varchar(30);
    key_var varchar(100);
    def_lang_var varchar(5);
    begin
    key_var := 'newString';
    def_lang_var := 'en';
    res := 'ap_string.htm';
    select count(*) into c FROM TRANSLATIONSTRINGS WHERE daKey = key_var AND daLanguage = def_lang_var;
    if c > 0 then
    select daSourceFile into res FROM TRANSLATIONSTRINGS WHERE daKey = key_var AND daLanguage = def_lang_var;
    end if;
    INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile) VALUES (key_var, 'cs', 'translation', 'N', res);
    end;
    However, such a query does not work in the query resource (multiline commands cannot be used?).
    Neither can I think of one line query that would provide the same functionality (tried to test with COALESCE).

    Yes, I got the point. The query looks like:
    INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile)
    SELECT daKey, daLanguage, daTranslation, daStringFlag, daSourceFile FROM (
    select 'newString1' daKey, 'en' daLanguage, 'transl' daTranslation, 'N' daStringFlag, daSourceFile FROM TRANSLATIONSTRINGS WHERE daKey = 'newString1' AND daLanguage = 'cs' UNION ALL SELECT 'newString1' daKey, 'en' daLanguage, 'transl' daTranslation, 'N' daStringFlag, 'default' daSourceFile FROM DUAL)
    WHERE rownum<=1;
    so that's the way how to solve it via SQL.
    (Since I can't use DECLARE, I need to bind entry parameters as many times as they appear in the query - not a very nice way, but it works).
    The question still is, whether there is a way how to use a multiline query in Component Queries. Even though it is not mentioned specifically in the documentation, it seems it is NOT to be possible by design. So the real question is really WHY - I guess it would be a little bit more convenient to begin/commit transactions, use variables, etc. in a multiline query.
    Yet, Sam, thanks!

  • Can i use icloud as storage and delete pictures from macbook?

    My macbook is currently full. I would like to know if i can move all photos/videos to icloud then delete them from macbook. My fear is the backup would run and realize they were not on the macbook then delete them from the cloud.

    I would like to know if i can move all photos/videos to icloud then delete them from macbook
    You cannot save space on your Mac by moving documents and photos to iCloud, because iCloud Drive will create shadow copies of every file it stores on your Mac. iCloud Drive is meant to keep all your documents updated on all devices.  (see this link:  iCloud Drive FAQ)  Using iCloud Drive you will need as much space as before, the advantage is that the drive will look the same on all your devices.  To save storage on your Mac get yourself an external drive and move  your photos to that drive. And make sure your new drive will be included in your Time Machine backup.
    Before you delete any files from your Mac, make sure, that you have at least one working backup and can read the moved files on the new drive.

  • Can´t use backspace in Safari for deleting text!?!

    In Safari i cant seem to be able to delete entrys with the backspace button.
    I can only delete text when using shift+backspace.
    Anyone experincing the same???
    Backspace works perfectly in Firefox and any other programme. Im using a MBA ultimo 2010.

    Try deleting the cache associated with Safari ...
    Open the Finder. From the Finder menu bar click Go > Go to Folder
    Type or copy/paste:    ~/Library/Caches/com.apple.Safari
    Click Go then move the Cache.db file from the com.apple.Safari folder to the Trash.
    Quit and relaunch Safari to test.

  • How can I use Ipad to view and delete photos from SD card without importing?

    Importantly I would like to view the photos from the SD card in full screen (vs. just a thumbnail) before deciding whether to delete.
    It seem's that with the camera connection kit you can only view them as thumbnails before importing. 
    Any other apps or hardware I could consider?
    Basically I would like to use the Ipad as my travel photo editing tool - specifically I want to be able to delete unwanted photos from my SD card without having to actually import them into the Ipad (but would like to be able to benefit from quality of ipad screen to actually review the photos before deleting).
    Thanks in advance for any tips you can share .....

    You must import if you want the iPad to have a file to display on the screen. 

  • Can you use CreatePDF to insert or delete individual pages in a PDF?

    I know this functionality is available in the Pro desktop version.

    Hi PeeDeeEffs,
    Sorry, but Insert, Delete, Extract, Replace pages functionality is only available Acrobat.
    Indeed, you may want to consider upgrading your CreatePDF subscription to Acrobat Plus subscription – that would allow you to download and use Acrobat XI Pro desktop application on your computer.
    And if that sounds interesting please check out Adobe Acrobat Plus pages for more info:
    https://www.stage.acrobat.com/acrobatplus/en/home.html
    Regards,
      Rufina
      Member of Adobe CreatePDF Team

  • I've been a member of creative cloud for months, everything worked fine, I deleted something and now anytime i open any  program i get an error that says my liscence is not working and I can not use any program, I've deleted all programs and now it won't

    h

    Paulietang do you know what files were deleted?  Which Adobe software or service gives you the error?  Have you tried removing and reinstalling the application?

Maybe you are looking for

  • "Unknown USB Device"

    I got my 2GB nano last Monday. I could successfuly install it on my laptop and upload some songs to it. That done, I wrapped it again and gave it to my wife, so she and the kids could "surprise" me for my Birthday. Yesterday I got it,listened to the

  • Does anyone have experience with XTC/C OR XTC/2 controller​?

    I am trying to use a serial connection to program an XTC/C controller.. if anyone can give me some help that would be great. I am running off of labview v6 and the examples given for serial I/O aren't responding to the machine.

  • Affordable hardware for VHS - PowerMac

    I am working on digitizing a large collection of VHS and 8mm home videos. So far I've been running the video through a digital camcorder to get it onto my PowerMac. The resulting sizes of the files is larger than it needs to be, since the digital cam

  • NullPointerException in BasicTableHeaderUI

    Hi, I am populating an JTable with some information. everything works fine but while populating table am getting following exception(still am able to populate table correctly) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at j

  • Can't believe I am asking this

    I am having a real brain freeze. What are the keys that advance or subtract 5 frames at a time on the timeline. Wow!! Age has set in.