MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 10th, 2000, 11:20 AM
ads
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.

Reply With Quote
  #2  
Old July 10th, 2000, 01:44 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
You need the DISTINCT keyword.

select distinct field_name ...

Reply With Quote
  #3  
Old July 10th, 2000, 11:41 PM
ads
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:

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.

Reply With Quote
  #4  
Old July 11th, 2000, 05:43 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
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

Reply With Quote
  #5  
Old July 11th, 2000, 08:16 AM
ads
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thanks a lot. It is working

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > SELECT statement problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway