#1
  1. No Profile Picture
    ads
    Guest
    Devshed Newbie (0 - 499 posts)
    There are rows in table having exactly identical field values. How to select only one of them by "SELECT" so that only one can be displayed.
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    You need the DISTINCT keyword.

    select distinct field_name ...
  4. #3
  5. No Profile Picture
    ads
    Guest
    Devshed Newbie (0 - 499 posts)

    Thanks
    I tried with this.

    $result = MYSQL_QUERY("SELECT DISTINCT FROM $userstable WHERE ((name = '$name') And (location = '$location')) ORDER BY ID DESC");
    It gives error.

    I do not know how to use DISTINCT in this case.
    Help appreciated.
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    It should be:

    select distinct some_field from $usertable where name='$name' and location='$location' order by ID desc

    you must specify the field name(s) that you want to retrieve just like any other select, but the distinct keyword in front of the field name specifies not to return multiples of the same value in that field
  8. #5
  9. No Profile Picture
    ads
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks a lot. It is working

Similar Threads

  1. switch statement problem
    By renato in forum PHP Development
    Replies: 5
    Last Post: December 18th, 2003, 03:35 AM
  2. Paging problem using parameter based SQL statement
    By socoolbrewster in forum ASP Programming
    Replies: 3
    Last Post: August 6th, 2003, 11:24 AM
  3. select sum( min()) problem
    By pogostik in forum MySQL Help
    Replies: 4
    Last Post: April 12th, 2003, 04:00 AM
  4. Replies: 1
    Last Post: December 7th, 2002, 09:26 PM
  5. select problem
    By m0nk3y in forum PHP Development
    Replies: 5
    Last Post: October 29th, 2001, 12:17 AM

IMN logo majestic logo threadwatch logo seochat tools logo