Problem with ordering in select query.

Hi,
We have the following query:
SELECT s.surveyid, m.messageid, m.text FROM MS_SURVEY s, MS_MESSAGES m where (m.messageid=s.survey_desc or m.messageid=s.survey_heading or m.messageid=s.user_profiles) and s.surveyid=xxx
This query selects 3 rows, one for description, one for heading and one for user profiles.
The problem is that, we have 4 databases. 2 Oracle 8.1.5, one Oracle 8.1.6 and one 8.1.7
This query when run on 8.1.7 and 8.1.5 will give us the result in the order:
1...description
2...heading
3...user profile
But, when run on 8.1.6 (which is the client setup of oracle)
The result is in the order:
1...user profile
2...heading
3...description
This project has still not been delivered because of this problem and we are already late by 2 months.
Please somebody let me know why this is happening?
I cannot change the code...as it has been tested for 1 month on staging setup, where it is working fine.
I have no clue as to why this is happening on the Client setup ONLY.
Is it a problem of different oracle versions, or any client side db trigger is there, or any options which the client has selected during his/her db installation or whatever...?
Kindly help.
Thank you.
Regards,
- Ram

Your query has no ORDER BY clause. Oracle does not guarantee (nor does any other RDB that I know of) to return rows in any particular order in the absence of an ORDER BY.
There are many factors that could affect the order in which rows will be returned in the absence of an eplicit ORDER BY clause. Among these are things like order of insertion of rows, access path chosen by the optimizer, the shoe size of the requestor.
You are going to have to change your code if you want a guaranteed order of the records.
TTFN
John

Similar Messages

  • Problem with JOINs in SELECT query

    The parameter  wa_dob-e_dob is not getting its definition ....
    it contains DOB in current yr.
    As i am using Joins also Workarea.... so is it coz Joins & WA cant be used simultaneously in a SELECT query....
    Is there any other option to do the same...?
    *  Global Structure
    TYPES : BEGIN OF t_data ,                     "Structure
            emp_dob TYPE pa0002-gbdat,
            emp_Mailid TYPE pa0105-usrid,
           END OF t_data,
           BEGIN OF t_dob,
           e_dob TYPE pa0002-gbdat,
           e_pernr type pa0002-pernr,
           END OF t_dob.
    *  Global Internal Tables (I_)
    DATA : i_data TYPE TABLE OF t_data,           "Internal Table for output data
           i_dob TYPE TABLE OF t_dob.             "Internal table for Dob
    *  Global Work Area (WA_)
    DATA : wa_data TYPE  t_data,                  "Work Area for output data
           wa_dob TYPE  t_dob.                    "Work Area for Dob
    *this is the query where i am getting error
    * Field "WA_DOB-E_DOB" Not found.
    LOOP AT i_dob INTO wa_dob.
        SELECT pa0002~gbdat pa0105~usrid INTO CORRESPONDING FIELDS OF wa_data
          FROM pa0002
          INNER JOIN pa0105
          ON pa0002~pernr = pa0105~pernr
          WHERE  pa0105~subty EQ 'MAIL' AND
         wa_dob-e_dob BETWEEN w_sysdate AND w_edit_sysdate.
        ENDSELECT.
        APPEND wa_data TO i_data.
        CLEAR wa_data.
        CLEAR wa_dob.
        CLEAR l_temp_dob.
      ENDLOOP.

    Hi,
    you are checking the work area in the SELECT. IN WHERE condition of the select u should specify fields in either of the tables pa0002 , pa0105 for data population.
    The select is on the database table and not on the work area.for checking the data in the work area do this way:
    loop at it_dob into wa_dob.
    if wa_dob-e_dob between the range u want (w_sysdate AND w_edit_sysdate)
    endif.
    endloop.
    ie: wa_dob-e_dob >w_sysdate AND wa_dob-e_dob < w_edit_sysdate or
        wa_dob-e_dob < w_sysdate AND wa_dob-e_dob  >  w_edit_sysdate
    watever ur requirement is..
    regards,
    madhu

  • Problem with order by clause

    Hai all,
    I have problem with order by clause,
    My query is
    "select number from table1 order by number asc "
    and the output is displaying as
    1
    10
    12
    13
    15
    17
    19
    2
    20
    21
    22
    But if we give order by it should display as below only right ?
    1
    2
    10
    12
    13
    15
    17
    19
    20
    21
    22 ........
    Please help me why it is not displaying like it. and how to make the statement to display like the second case. Thanks in advance.
    Regards,
    Uraja

    The column datatype that you are selecting is not of NUMBER datatype(might be char or varchar2) hence you are getting such result set.
    And for this purpose, it is recommended to set datatype of a column appropriately.
    For now you can add TO_NUMBER function to column in ORDER BY clause, only if it has data of number type.
    Edited by: Ora on 19 Nov, 2012 3:10 AM

  • Problem with 'order by' and comparison operator with varchar2 field

    I have a problem with the following sql query (field1 is varchar2):
    SELECT field1
    FROM tablename
    WHERE field1 > 'AA10BB'
    ORDER BY field1
    The contents of field1 is:
    AA10BB
    AA10-10BB
    AA10-12BB
    The sql query without the WHERE clause sorts field1 this way:
    AA10BB
    AA10-10BB
    AA10-12BB
    But the sql query with the WHERE clause has no hits.
    It seems that when sorting the minus character is greater than the 'B' character and
    at the comparison ( > 'AA10BB' ) the minus character is lower than the 'B' character!
    The database and client NLS_PARAMTER are GERMAN_GERMANY.
    The database is 9.2.0.7
    Has anyone an idea?

    thanks for your fast reply!
    My problem was that NLS_SORT was set to 'GERMAN' and NLS_COMP to 'BINARY'.
    NLS_SORT = GERMAN orders the varchar2 fields in form of 'a A b B ... 0 1 2 3 ..'
    NLS_COMP = BINARY compares binary (ASCII-Table).
    I use now:
    SELECT field1
    FROM tablename
    WHERE field1 > 'AA10BB'
    ORDER BY NLSSORT(field1, 'NLS_SORT = Binary'');

  • Problem with order data

    Hi, I have a problem with order data. A string column has these values:
    A....
    B....
    PSTA-FRA
    PSTA+FRA
    Q....
    R....
    If i order data directly from db ( select column1 from table order by column1 ) , i obtain this result:
    PSTA-FRA
    PSTA+FRA
    If i create a simple report on that table and order on that column the result is:
    PSTA+FRA
    PSTA-FRA
    I can obtain correct output if I set parameter 'Perform group on server' but if i write a selection formula :
    {table.column} >= 'PSTA+FRA'
    record containing PSTA-FRA value not appear.
    I've tried both with Crytal 8.5 and Crystal 11 R2 sp6, database is Sybase SQL Anywhere odbc connection.
    Thanks in advance

    Ordering is done according to the ASCII values of the characters.
    In R2 create a new report and log onto your DB and select Command for your data source. Paste in the SQL you use to get the data in the order the server users. Then you don't have to use CR to do the sorting. DB Servers are much more efficient at collecting the data than CR is.
    Thank you
    Don

  • Hi! Everyone, I have some problems with JOIN and Sub-query; Could you help me, Please?

    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!

    Hi,
    fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
    Dear Sir/Madam
    I'm a student who is interested in Oracle Database and
    I have some problems with JOIN and Sub-query.
    I hope so many of you could help me.
    if i use JOIN without sub-query, may it be faster or not?
    SELECT field1, field2 FROM tableA INNER JOIN tableB
    if i use JOIN with sub-query, may it be faster or not?
    SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
    Thanks in advance!
    As the others have said, the execution plan will give you a better idea about which is faster.
    If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible.  For example, include field3 in both queries, or ignore field3 in both queries.
    In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess.  I can't see your execution plans.
    In general, simpler code is faster, and better in other ways, too.  In this case
    tableB
    is simpler than
    (SELECT field1, field2  FROM tableB)
    Why do you want a sub-query in this example?

  • Problem with order in iPhoto

    problem with order in iPhoto. I can't buy a card, because there comes an Message "Ihre Karte enthält offenbar Standardtext, der noch nicht bearbeitet wurde. Gedruckte Karten enthalten diesen Text nicht. Möchten Sie fortfahren?" What should I do?

    That message means that you have text boxes that have not been used.  The holding text that appears in the box will not be printed. But if you want to get rid of the warning just put a space in the text box.
    OR, check to see if the card layout has the same page but without a text box.  Most do.
    OT

  • F-32 : Problem with Open Item selection

    Hi,
    We have a strange problem with open Item selection for customer clearing in t-code F-32
    In My QA system
    if I input spl GL indicator ="*" and uncheck Normal OI tick,
    the system selects all open items,
    (those with spl GL indicator and those without spl GL indicator)
    In My Dev system
    If I input spl GL indicator ="*" and uncheck Normal OI tick
    the system does not select any open items,
    Please let me know which setting controls this behaviour ?
    Regards
    Sachin

    Hello,
    Check your data in FBL5N for the option "Special GL Transactions". There could be that there is no data in the system with SPECIAL GL TRANSACTIONS.
    In F-32, there is no value like *
    You need to input right Special GL Indicator. "*" will not work here.
    I am sure in both the systems if you put "*" and UNTICK your normal transaction, you will NOT get any items to clear.
    Please DOUBLE CHECK whether you have unticked normal transaction.
    Regards,
    Ravi

  • To select particular rows from order by select query

    Hi all,
    I want to select particular rows from a order by select query like...
    select * from emp order by ename;
    If i pass 3 and 7 dynamically in where clause or something like that, it has to show rows from 3 to 7 only.
    Thanks in advance
    Pal

    This?
    SQL> select *
    from (
       select e.*,
          row_number() over (order by ename) rn
       from emp e)
    where rn in (3,7)
    EMPNO ENAME      JOB         MGR HIREDATE         SAL       COMM     DEPTNO RN
    7698 BLAKE      MANAGER    7839 01-MAY-81       2850                    30  3
    7566 JONES      MANAGER    7839 02-APR-81       2975                    20  7
    2 rows selected.

  • HT1338 Problem with MAIL, when select names that start with "E" the mail freeze. Can't fix it.

    Problem with MAIL, when select names that start with "E" the mail freeze. Can't fix it.

    Now I checked the materials that I got from AT&T Yahoo and
    port 25 is used as the outgoing mail port, 110 for incoming.
    This is for the POP type account provided by AT&T, not necessarily for an email account and SMTP server not provided by AT&T.
    Sounds like AT&T blocks using an SMTP server that is outside of their network or not provided by AT&T on Port 25.
    Try the following first.
    Go to Mail > Preferences > Accounts and under the Account Information tab for your .Mac account preferences at the SMTP server selection, select the Server Settings button below for the .Mac SMTP server.
    Enter 587 in place of 25 in the Server Port field and when finished, select OK to save the changed setting.
    If this doesn't work, we will go to plan B.

  • Problem with performance of a query having order by, distinct clause

    Hi,
    I have a problem with queries having order by, distinct clause.
    While its executing its taking lot of time. With DBMS_PROFILER identified the queries taking long time.
    The table is having approximately 70 million rows.
    Problem -1
    select * from table_name order by col1;
    select distinct col1,col2 from table_name;
    Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.
    Solution1:
    Max parallel servers is 8.
    select /* + parallel(table_name,8) */ * from table_name order by col1;
    select /* + parallel(table_name,8) */ distinct col1, col2 from table_name ;
    Solution-2:
    select /* + first_rows */ * from table_name order by col1;
    select /* + first_rows */ distinct col1, col2 from table_name ;
    Problem-2
    I am having a query with where condition on columns.
    Select * from table_name where col1='value1' and col2!='value2';
    Index created on col1 and col2.
    As we no that not equal won't use index as it is a composite index it should use the lead column. but its not using the index.
    Should i forcibly use index with hint or suggest me better solution.
    Any help really appreciated.
    Thanks in advance

    unique wrote:
    The table is having approximately 70 million rows.
    select * from table_name order by col1;Do you really want 70,000,000 rows from your table without any restrictions ? And furthermore ordered output ? I honestly understand the slowness of that query.
    Here i am having 2 solutions request to let me know whether i am right if not suggest me right solution.Who knows if you choosed the right solution. I would suggest to reconsider your query and the need of 70,000,000 returned rows.
    Problem-2
    I am having a query with where condition on columns.
    Select * from table_name where col1='value1' and col2!='value2';Please, provide the explain plan, eventually the tkprof output could also help. And tables descirption AND indexes description.
    And OS and Oracle version.
    Nicolas.

  • Problem with LIMIT in my query...

    I am sending this query with JSP to my Oracle database:
    SELECT pub, class, startdate, adtext FROM classifieds WHERE (pub='KWR') AND
    (startdate<='03-Jan-02') ORDER BY pub LIMIT 0, 25
    I keep getting the error:
    "Exception=java.sql.SQLException: ORA-00933: SQL command not properly ended"
    If I remove the LIMIT 0, 25 it works just fine and returns all records, what am I doing wrong?

    numrows=>26 AND numrows<=50 I doubt that that will work either. But you can try. Oracle has something like that (although I am not sure is is called 'numrows'). However, it doesn't allow ranges. It allows you to return only the top ones (the less than expression) And it doesn't work with order by clauses.
    Someone, sometime ago, suggested a solution in this forum which solved both of these problems. If you search for the correct keyword (not 'numrows') you will likely find it.

  • Problem with cascading dependent LOV query running when it should not

    I have a page fragment with a regular ADF form on it that I use to add new entries to a table. This form has many fields on it with LOV’s associated with them. I have dependent LOV’s on some of them. The one case I have is I have three fields A, B, and C. Field C is dependent on A and B. The problem I seem to be having is when I enter a value for field A using it’s LOV, I get an hourglass for a long time after I select it and before it is displayed on the form. If I delete field C from the form the problem goes away. If I change the query behind the view for the LOV for field C to include a rownum < 20 in the where clause the problem goes away. My question is, why would the selection of a value for field A cause the query to fire for field C’s LOV view and how can I stop it. I don’t really want to use the rownum in the where clause.

    i had lot of question?
    The problem I seem to be having is when I enter a value for field A using it’s LOV, I get an hourglass for a long time
    ok. are using? any complex query to pick the lov 'a' .
    Answer: The LOV for A is based on a read only non-EO view with a SQL that is not really very complex. The LOV definition does set multiple values when the selection is made to blank out dependent fields in the data model used by the main form.
    after I select it and before it is displayed on the form.
    here i cant undestud?
    Answer. The order of things is I open the main form, I click the mag glass to open the LOV popup, I select the row I want and click the OK button. Navigation returns to the main form where I get the hourglass waiting for the selected value to be displayed in the field on the main form.
    If I delete field C from the form the problem goes away. If I change the query behind the view for the LOV for field C to include a rownum < 20 in the where clause the problem goes away.
    ok.
    why are you going to delete the value of c?. At intial stage you can make empty after selecting a and/or b you can load into c.
    Answer: I physically deleted field C from the main form to see if that was what was causing the long delay. When I run the main form without field C I do not get the hourglass. That is how I know they are related.
    My question is, why would the selection of a value for field A cause the query to fire for field C’s LOV view and how can I stop it.
    you may set partial trigger to c depends for 'a'.
    or else lov 'c' query depends on 'a'
    Answer. The query for C's LOV does depend on the value returned when I select a value for A. They are cascading LOV's. Will setting the partial trigger stop the SQL for field C from running? Is the SQL running because I'm blanking out field C when I change the value for field A?
    am not sure i understud correctly. can you pictuarize you problem with an example.

  • Problem with parameter and sql query

    I've a problem with te query of my report. The query is:
    SELECT [DESCRIPTN]
          ,[LOGTIME]
          ,[STATUS]
          ,[CARDNO]
          ,[LOGDATE]
    FROM [Granta5P0].[dbo].[TIMELOG32]
    where cardno in ({?cardNo})
    the parameter as multiple values checked so I can query for more than one card.
    If i put just one parameter everything works fine but when I put 2 or more I have his error
    [http://www.megagaleria.com/pictures/Pic_10074_25.jpg]
    I realized that the field as no ' delimiting the parameters, I have a function that already does it but I don't know how to put it in my sql command.
    If anyone can help I appreciate

    Yes, because your parameter is only looking for one card.
    where cardno in ({?cardNo})
    Will you only be creating querys on two cards or less ?
    Are you trying to create an Array?
    If two or less you could
    where cardno = ({?cardNo}) or cardno = ({?cardNo2})

  • A problem with LOV and my query. Help to solve, please...

    Hello!
    Here is a query:
    SELECT FULLNAME||', '||(SELECT NAMEOFGROUP||', '||(SELECT CITY FROM CITY WHERE PRKEY=TLL.CITY) FROM GROUPS TLL WHERE PRKEY=TL.GROUPOF) t ,PRKEY r FROM MINEUSERS TL
    In SQL DEVELOPER it works fine. But in APEX - when I try to save my "SELECT LIST" - it falls with error - "If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query."
    How can I reassemble my query to fix this problem - I have no idea... :(
    Thanks

    You may create a pipelined function returning two values, display and return, to return
    the result from your query. After that, your LOV should work. See example here:
    http://htmldb.oracle.com/pls/otn/f?p=31517:146
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://htmldb.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

Maybe you are looking for

  • ACS 5.3 and Command Auth

    I am rolling out the Latest 5.3.0.40.6 patched ACS 1121 in a redundant pair mode.   I have build user based auth without issue but am having an issue with Command auth.  once I add command auth to the test router and modify the shell profile and comm

  • Difficulty with syncing videos??

    I am trying to add some videos to my ipad by syncing through my itunes. When I connect my IPAD to the PC to complete the sync it wont let me sync it says that I have 24GB of videos on my IPAD yet under movies and TV shows there are no videos. How can

  • 6d raw in elements 11

    Hi, i recently bought elements 11 to use with my Canon 6d. The raw converter (Ver 7.1.0.354) doesn't recognise the files from the camera, the updates option under the help tab is telling me that everything is up to date, Help!!!

  • Dead Superdrive solution...kind of...

    My superdrive (pioneer 106D) stop working again (replaced about 1,5 years ago); as recommended I zapped PRAM (commandoption+PR) 3x times boing, repair permissions, restart again; Toast 6 still doesn't work BUT; burning from the Finder works !, you ne

  • SD DV import problem

    I am trying to import into Final Cut Pro X old SD NTSC DV tapes from a camera I no longer have. Most of the time (but not every) FCP stops importing the clip after 2 minutes and 13 seconds. I have tried different cameras, cabling, and storage locatio