SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Clause ORDER BY

  1. #1
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Clause ORDER BY

    Hi there, I need your appreciated help.

    The table `_tbl_C`:
    Code:
    ID	MCR_Cod		MCR_Den
    1	DCE 		DCE - MAC
    2	DNE  		DNE - MNE
    3	DNO		DNO - MNO
    4	DSU		DSU - MSU
    The SQL Query:
    Code:
    SELECT C.MCR_Cod 
         , C.MCR_Den 
       FROM _tbl_r R INNER JOIN _tbl_C ON 
          R.CFT_Cod = C.CFT_Cod 
       WHERE 1 
    GROUP BY C.MCR_Cod 
           , C.MCR_Den;
    In the output I have this order (no clause in the sql query):
    Code:
    MCR_Cod
    DCE
    DNE
    DNO
    DSU
    I need this other output:
    Code:
    MCR_Cod
    DNO
    DNE
    DCE
    DSU
    Can you help me?
    Thanks in advance.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    your query doesn't match your table (there is no CFT_Cod column), but i guess that's not important to your question

    the GROUP BY seems redundant, but maybe that's because you have redundant data, so i guess that's not important to your question

    Code:
    ORDER 
        BY CASE WHEN MCR_Cod = 'DSU' 
                THEN 'humpty' 
                ELSE 'dumpty' END
         , MCR_Cod DESC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I can't thank you enough for the help. That worked perfectly.


Bookmarks

Posting Permissions

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