List:General Discussion« Previous MessageNext Message »
From:tony Date:July 2 1999 4:14pm
Subject:SELECT WHERE id = MAX(id)
View as plain text  
I have a table that looks like:

CREATE TABLE foo (
  id mediumint(8) unsigned DEFAULT '0' NOT NULL auto_increment,
  amount decimal(5,1) DEFAULT '0.0' NOT NULL,
  PRIMARY KEY (id)
);

INSERT INTO foo VALUES (1,,13.5);
INSERT INTO foo VALUES (2,,13.6);
INSERT INTO foo VALUES (3,,12.0);
INSERT INTO foo VALUES (4,,14.8);


How can get the amount for the maximum id in one query?

I would have thought something like:

SELECT id, amount FROM foo HAVING id = max(id)

but that gives me an empty set...

And I can't manage to do it with an explicit GROUP BY ...

Anyone?

[Server version          3.22.20a    
 System: Linux 2.2.7 #2 SMP]

Tony
-- 
-----------------------------------------------------------------------------
 Tony Bowden | tony@stripped               http://www.blackstar.co.uk/
  Black Star |    The UK's Biggest Video & DVD store * Free Postage Worldwide
-----------------------------------------------------------------------------
Thread
SELECT WHERE id = MAX(id)tony2 Jul
  • Re: SELECT WHERE id = MAX(id)Paul Wolstenholme2 Jul
    • Re: SELECT WHERE id = MAX(id)tony2 Jul
  • Re: SELECT WHERE id = MAX(id)Martin Ramsch2 Jul
    • Re: SELECT WHERE id = MAX(id)Steve Ruby2 Jul
Re: SELECT WHERE id = MAX(id)tony3 Jul
  • Re: SELECT WHERE id = MAX(id)Steve Ruby3 Jul