DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Question on Order By clause

  1. #1
    Join Date
    Dec 2000
    Posts
    95

    Question Question on Order By clause

    HI,

    I have a small question regarding the Order By clause. Please check the following query.

    select
    *
    from
    course
    order by
    course_name desc,title desc

    and the output is as follows

    Courseid ---- Tilte ---- course_name ---Duration
    --------------------------------------------------------------
    100168--MFC Fundamentals II-- wp202-- 15
    100192--Win32 API Fundamentals II-- wp201-- 15
    100121--MFC Fundamentals I-- wp102-- 15
    100119--Win32 API Fundamentals I-- wp101-- 12
    100281--UNIX Network Administration II-- ux700-- 8
    100277--UNIX Network Administration I-- ux600-- 8
    100227--UNIX System Administration I-- ux400-- 8
    100573--Red Hat Linux Security (a)-- ux303-- 8
    100326--Advanced UNIX Shell Programming-- ux301-- 10
    100029--Creating Basic UNIX Shell-- sa0029-- 10
    100582--Red Hat Linux Networking-- pm107-- 10
    ********************************************************************

    if you observe the above result, in the query I have added two columns to the Order By clause. One is "Course_Name" and the other one is "Title". I want to sort both "Course_Name" and "Title" in descending order. But the query is taking only the "Course_Name" in descending order and ignoring the "Title" descending order.

    If i try as follows
    "select
    *
    from
    course
    order by
    short_name,title desc"

    now both the "Course_Name" and "Title" are sort by descending order.


    How should I write query to get the output with two columns in descending order? Any mistake in my above query? Could you please help me regarding the same?

    Thanks in advance.

    Regards,
    Srinivas Medukonduru

  2. #2
    Join Date
    Jul 2002
    Location
    Slovenia
    Posts
    42
    I THINK IT IS SORTED OK.

    IF YOU WOULD HAVE TVO LINES WITH SAME COURSE NAME AND DIFFERENT TITLE IT WOULD ORDER TITLE IN DESCENDING ORDER

    EXAMPLE:

    100168--MFC Fundamentals D-- wp202-- 15
    100169--MFC Fundamentals C-- wp202-- 15
    100170--MFC Fundamentals B-- wp202-- 15
    100171--MFC Fundamentals A-- wp202-- 15


    order by
    course_name desc,title desc


    ********************************************************************
    Andrej

Posting Permissions

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


Click Here to Expand Forum to Full Width