Re: select row with greatest valued column - let me try again

2006-12-08 Thread Peter Bradley
Ysgrifennodd Tim McIntyre: Next pint is on me Peter;-) The following turned out to be exactly what I needed: SELECT s1.id FROM status_histories s1 WHERE s1.type = 'StatusHistoryOrder' AND s1.code = 1 AND s1.created_at = (SELECT MAX(s2.created_at) FROM statu

Re: select row with greatest valued column - let me try again

2006-12-08 Thread Tim McIntyre
Next pint is on me Peter;-) The following turned out to be exactly what I needed: SELECT s1.id FROM status_histories s1 WHERE s1.type = 'StatusHistoryOrder' AND s1.code = 1 AND s1.created_at = (SELECT MAX(s2.created_at) FROM status_histories s2

Re: select row with greatest valued column - let me try again

2006-12-08 Thread Peter Bradley
Ysgrifennodd Tim McIntyre: I tried that Peter and for some reason it's still selecting the oldest date not the newest??? Seems odd? Also I'd really like to just select id because I'll be using this in a subselect. Thanks! Tim SELECT s1.order_id FROM status_histories s1 WHERE s1.type = 'Statu

Re: select row with greatest valued column - let me try again

2006-12-08 Thread Tim McIntyre
I tried that Peter and for some reason it's still selecting the oldest date not the newest??? Seems odd? Also I'd really like to just select id because I'll be using this in a subselect. Thanks! Tim On Dec 8, 2006, at 10:31 AM, Peter Bradley wrote: Ysgrifennodd Tim McIntyre: Thanks for th

Re: select row with greatest valued column - let me try again

2006-12-08 Thread Peter Bradley
Ysgrifennodd Tim McIntyre: Thanks for the responses guys however I was running out the door yesterday and I oversimplified my problem. Sorry about that, let me try again. Here is my "status_histories" table with some data: id order_id code type

Re: select row with greatest valued column - let me try again

2006-12-08 Thread Tim McIntyre
Thanks for the responses guys however I was running out the door yesterday and I oversimplified my problem. Sorry about that, let me try again. Here is my "status_histories" table with some data: id order_id code type created_at 79 1

Re: select row with greatest valued column

2006-12-07 Thread mos
At 03:10 PM 12/7/2006, Tim McIntyre wrote: Hey all I would guess this would be a pretty simple question. How do I select a row whose value for a given column is the greatest or the least or whatever for that table? e.g: select * from table where creation_date > all_other_creation_dates; Hope

Re: select row with greatest valued column

2006-12-07 Thread Dan Buettner
It's actually pretty easy - select * from table order by creation_date desc limit 1 Now one catch to this use of LIMIT is that you only get one row - even if there are multiple rows that share the same greatest creation_date. Sometimes that's acceptable, sometimes not. Dan On 12/7/06, Tim McI

select row with greatest valued column

2006-12-07 Thread Tim McIntyre
Hey all I would guess this would be a pretty simple question. How do I select a row whose value for a given column is the greatest or the least or whatever for that table? e.g: select * from table where creation_date > all_other_creation_dates; Hope that makes some sense. Thanks in advance