List:General Discussion« Previous MessageNext Message »
From:Erik Liljencrantz Date:April 29 1999 11:53am
Subject:Re: Select most recent row - another one for the FAQ perhaps?
View as plain text  
At 13:15 1999-04-29 +0200, Christian Mack wrote:
>[...suggested queries skipped...]
>Hi Robin
>
>This don't work, because MAX() is a group function, which can't be used in 
>WHERE clauses (defined by SQL standard).
>
>Therefore it is impossible to get what Fred wants to get in one query.

Maybe I'm missing something, but "order by fieldname desc limit 1" usually
gets me the record where the field has the largest value (or smallest
without desc).

In this case:
  select UserName, Created
    from MyTable
    where UserName = 'MyUserName'
    order by Created desc limit 1

To simple to work? mySQL knows how to optimize this type of query.

Regards,
  Erik L.

---
Erik Liljencrantz, E-ell-Data, http://www.eldata.se
erik@stripped, +46 150 250 58, +46 70 51 8 51 26
Aspenaes, 640 25 JULITA, SWEDEN
Thread
Select most recent row - another one for the FAQ perhaps?Fred Read29 Apr
  • Re: Select most recent row - another one for the FAQ perhaps?Robin Bowes29 Apr
  • Re: Select most recent row - another one for the FAQ perhaps?Fred Read29 Apr
  • Re: Select most recent row - another one for the FAQ perhaps?Robin Bowes29 Apr
  • Re: Select most recent row - another one for the FAQ perhaps?Christian Mack29 Apr
    • Re: Select most recent row - another one for the FAQ perhaps?Fraser MacKenzie29 Apr
      • Re: Select most recent row - another one for the FAQ perhaps?Fred Read29 Apr
        • Select most recent row - another one for the FAQ perhaps?Fraser MacKenzie29 Apr
    • Re: Select most recent row - another one for the FAQ perhaps?Erik Liljencrantz29 Apr
  • Re: Select most recent row - another one for the FAQ perhaps?Fred Read29 Apr
    • Re: Select most recent row - another one for the FAQ perhaps?Michael Longval1 May
      • Re: Select most recent row - another one for the FAQ perhaps?Thimble Smith1 May
  • Re: Select most recent row - another one for the FAQ perhaps?Robin Bowes29 Apr
    • Re: Select most recent row - another one for the FAQ perhaps?Erik Liljencrantz29 Apr
      • Re: Select most recent row - another one for the FAQ perhaps?Michael Widenius30 Apr