Results 1 to 4 of 4

Thread: db2 Sql

  1. #1
    Join Date
    Aug 2012
    Posts
    14

    Unanswered: db2 Sql

    Hi - We have db2 V9 database.

    please help me that the rows with the smaller ID numbers are returned first. I'm not 100% sure how to modify the indexes to do this. I checked all the common files in our normalizer and this is the current query used where the order of the results matter.

    SET query = 'SELECT P.BUSINESS_NAME, A.STREET_NO, A.STREET_NAME, A.CITY, A.ZIP_POSTAL_CODE, A.STATE_PROV, A.COUNTRY,

    C.FIRST_NAME, C.LAST_NAME, C.PHONE, C.EMAIL

    FROM IDS.PARTICIPANT_ADDRESS AS A, IDS.PARTICIPANT AS P, IDS.PARTICIPANT_CONTACT AS C

    WHERE P.ID = ? AND P.ID = C.PARTICIPANT_ID AND P.ID = A.PARTICIPANT_ID AND C.ROLE_ID= (SELECT R.ID FROM IDS.ROLE AS R WHERE R.NAME = ?)';

    Please advise on how to make sure that the above query returns the smaller ID rows first.

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Try using ORDER BY on the SELECT. DB2 does not guarantee the order of a result set unless the ORDER BY is used.

    Andy

  3. #3
    Join Date
    Aug 2012
    Posts
    14
    Thanks for your quick response. Please explain little more that on which col i can use order by to get smaller id.

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Please read the manual (it is free). It will explain the ORDER BY clause. Only you know how you want it sorted.

    Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •