Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 13-03-2007, 06:28 PM   #1 (permalink)
~[::BOoYaKa::]~
 
Join Date: May 2005
Location: In a Cave.
Posts: 575
Default mySQL query help


i have a table with fields name, time, and userid. I want to select name and time, such that no name is duplicated i.e. no same names should be returned and the result should be sorted by time(DESC). I cant make a query for this. Can someone help.
I tried this query but it doesnt work::
Code:
SELECT DISTINCT(name), time FROM table_name WHERE visitorid='1' ORDER BY time DESC;
but it gives error.
Thanx.
__________________
[::Eddie n Benoit Live Forever::]
REY619 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 13-03-2007, 06:42 PM   #2 (permalink)
Wise Old Owl
 
The Unknown's Avatar
 
Join Date: Nov 2006
Location: Pune, Maharashtra, India
Posts: 1,728
Default Re: mySQL query help

^^ Explain properly.
__________________
KDE on ArchLinux
PHP, MySQL, PostgreSQL, Linux, Apache; Message me to hire (freelancing only)
Explore Technology @ http://www.itech7.com
Cheap and Reliable VPS Hosting @ http://j.mp/arHk5e
The Unknown is offline  
Old 13-03-2007, 06:54 PM   #3 (permalink)
Back to School Mr. Bean !
 
mod-the-pc's Avatar
 
Join Date: Apr 2004
Location: Chennai
Posts: 343
Default Re: mySQL query help

Quote:
Originally Posted by REY619
i have a table with fields name, time, and userid. I want to select name and time, such that no name is duplicated i.e. no same names should be returned and the result should be sorted by time(DESC). I cant make a query for this. Can someone help.
I tried this query but it doesnt work::
Code:
SELECT DISTINCT(name), time FROM table_name WHERE visitorid='1' ORDER BY time DESC;
but it gives error.
Thanx.
@REY619 a DISTINCT clause selects the distinct combinations of the fields in the SELECT clause (i.e. name & time in your query) and NOT just the distinct values of a single field. I guess that your table has more than one time associated with a name i.e. more than one record for the same name. You can just choose the max (or min) of time to ensure that the name is not repeated

Code:
SELECT 
  name, 
  max(time) as MAX_TIME 
FROM 
  table_name 
WHERE 
  visitorid='1' 
GROUP BY 
  name 
ORDER BY 
  MAX_TIME DESC;
__________________
Desktop: P4 2.8E, Intel 865GBF, 512MB Hynix PC3200, Samsung SV1204H 120GB, Samsung SW-248F, Creative Inspire 4400, Samsung 793MB, Compro PVR/FM, WinLIRC

Laptop: HP Pavilion dv8210us
mod-the-pc is offline  
Old 14-03-2007, 11:56 AM   #4 (permalink)
~[::BOoYaKa::]~
 
Join Date: May 2005
Location: In a Cave.
Posts: 575
Default Re: mySQL query help

Thanx mod-the-pc will try that
__________
Thanx its working!!!
__________________
[::Eddie n Benoit Live Forever::]

Last edited by REY619; 14-03-2007 at 11:56 AM. Reason: Automerged Doublepost
REY619 is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Sujeet
- by Krow
- by abhidev
- by topgear

Advertisement




All times are GMT +5.5. The time now is 07:41 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2