SELECT DISTINCT sensor_id, other_fields FROM table_name ORDER BY time_stamp_field DESC LIMIT 40
Not sure if that will work, but does it point you in the right direction? j----- k----- On Saturday 06 March 2004 07:22 pm, Tim McDonough wrote: > On Sat, 06 Mar 2004 20:40:24 -0600, Paul DuBois wrote: > > You can use your LIMIT clause as well, as long as by that you don't > > mean "5 most recent from *each* table". > > This seems similar to something I'm working on which I haven't sorted > out to my satisfaction yet. > > We have a system that collects and stores data that is time stamped in > a mysql database. There is data from 40 sensors and it does not arrive > at exactly the same time so each sensor reading and it's time stamp > are stored. The table contains a date/time, the sensor ID, and the > value. > > One request is to have a web page that will display each sensor and > it's most recent measurement so the most recent is always shown. > regardless of which sensor it came from. How do I create a query that > will extract the most recent data (latest date) from the database for > each of the sensors and have it sorted it by the sensor ID? > > This isn't obvious to me from reading the documentation on queries and > I've been searching and reading through messages without success yet. > I suspect a big part of the problem is I'm fairly new to sql queries > and am not exactly sure what terms to search for. > > Tim -- Joshua J. Kugler Fairbanks, Alaska Computer Consultant--Systems Designer .--- --- ... .... ..- .- -.- ..- --. .-.. . .-. [EMAIL PROTECTED] ICQ#:13706295 Every knee shall bow, and every tongue confess, in heaven, on earth, and under the earth, that Jesus Christ is LORD -- Count on it! -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]