SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: ORDER BY DESC

  1. #1
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys,

    I'm trying to ORDER a SELECT statement of mine. It works, but when I try to put it in desceding order, it still stays in ascending order. Here's my query:

    Code:
    $sql = mysql_query("SELECT DISTINCT members.ID AS UID, LN, FN, members.City AS MCity, HE, WE, WP, HP, members.WID, work.ID, work.Name AS WName FROM users, members, work WHERE members.WID=work.ID ORDER BY LN, FN DESC LIMIT $num,20");
    THe SELECT thing still returns a few rows, but it's in ASC (ascending order), not DESC (descending order). Anyone what I'm doing wrong?

    aDog

  2. #2
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Also, when I don't use the DISTINCT keyword, it seems to return 2 sets of rows (for each one row it's supposed to...it duplicates it), even in phpMyAdmin. There are no duplicate rows or anything as all have distinct ID's.

    aDog

  3. #3
    SitePoint Zealot moshe_be's Avatar
    Join Date
    Dec 2000
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to change your order by from:
    ORDER BY LN, FN DESC

    to:

    ORDER BY LN DESC, FN DESC

    This will sort first by last name DESC, then by first name DESC.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You say that you are getting two of each record if you don't use distinct.

    Let me guess that you only have two records in table "users"?
    Also, are any of the fields that you have in your SELECT clause from the table "users".
    I suspect that you are not using any fields from table "users".
    If this is so, then remove users from your "FROM" clause.

    If there are fields from table "users" in your SELECT clause then you should create a
    filter in your WHERE clause - otherwise you will get too many rows in your
    result set. Eg:

    WHERE members.WID=work.ID
    AND users.ID = members.WID

    Something like that.

  5. #5
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Both of you got it...thanx sooo much you guys

    Cheers,
    aDog


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
  •