SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL - How can I SELECT from last to first

    How can I Select and get from the end on the list
    instade from the start?

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should probably ask the question in the appropriate forum (this is PHP, not SQL) and give more info about what you want and what you have at your disposal.

    To cut it short, you don't "select from the end", you give the select criteria and order the result the way you want to see it (ascending / descending) based on a key. You probably need some condition to filter unwanted results too.
    It's easy to google it out with information I provided so I won't post examples.

  3. #3
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Just type the following code in mysql

    SELECT EMP_NAME FROM EMP_TABLE
    WHERE EMP_NUMBER=1000
    ORDER BY EMP_NAME DESC
    FETCH FIRST n ROWS ONLY


  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by raj23 View Post
    FETCH FIRST n ROWS ONLY
    In MySQL this is called LIMIT.

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    not only is the syntax wrong for mysql, raji, but that's a very sloppy example

    your WHERE clause identifies a single employee, so there won't be more than one row to sort, much less take the first n rows of...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •