[DB-SIG] Select question

Mike C. Fletcher mcfletch at rogers.com
Wed Jan 21 23:47:31 EST 2004


    SELECT DISTINCT ( a ), * FROM t ORDER BY c DESC;

DISTINCT chooses the first row from the result set with equal distinct 
As, which, with the ordering of the set by C descending, should be the 
value with the maximal C value (first row of the items duplicating A for 
each A).  I'm going from postgresql background, but I think everything 
there is standard SQL operation.

That's a very weird problem description, btw.  Why the heck does someone 
need the nearest "Joe"?  I can think of a few applications with 
intellisense-like mechanisms, but doesn't really seem like a natural 
approach.

Oh well, HTH,
Mike

Conrad Koziol wrote:

>This isnt really about python but I was hoping you could help me with a
>tricky select question. The problem I have is that I need to select a
>distinct item from column A, but it has to be the item with the greatest
>value in C. So if column A holds all the birthdays of joes and bobs, I
>need to select the joe and bob with the closest birthday(youngest). I am
>using MySQL 4.0.15.
>
>Thanks a lot!!
>	Conrad
>  
>
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/





More information about the DB-SIG mailing list