Re: simple but frustrating query

2004-10-15 Thread Jeff Mathis
i don't think i missed any points raised by anyone in this discussion. email is often a difficult medium for technical issues. for most of our purposes, we run multiple queries in order to make sure we are actually getting the data we want. it makes the code simpler, easier to understand and

simple but frustrating query

2004-10-14 Thread Jeff Mathis
hello query gurus. we have a table TD with the following columns: close_date symbol name close_date is just a date field there is a unique constraint on the combination of close_date and symbol. what we want is the value for the name field corresponding to the row with the most recent close_date.

RE: simple but frustrating query

2004-10-14 Thread Ed Lazor
-Original Message- what we want is the value for the name field corresponding to the row with the most recent close_date. Based on that comment, I'd select name from TD order by close_date DESC limit 1 something like this: select max(close_date), symbol, name from TD where

Re: simple but frustrating query

2004-10-14 Thread Jeff Mathis
Ed Lazor wrote: -Original Message- what we want is the value for the name field corresponding to the row with the most recent close_date. Based on that comment, I'd select name from TD order by close_date DESC limit 1 except, we run into problems when there is a list of values for symbol

Re: simple but frustrating query

2004-10-14 Thread Joe Audette
How about select close_date, symbol, name from TD where symbol in (list of characters) limit 1 ORDER BY close_date desc Jeff Mathis [EMAIL PROTECTED] wrote: hello query gurus. we have a table TD with the following columns: close_date symbol name close_date is just a date field there

Re: simple but frustrating query

2004-10-14 Thread Jeff Mathis
I'll be more explicit: select max(close_date), symbol, name from TD where symbol in ('aa','bb','cc') group by symbol, name order by symbol; returns +-++-+ | max(close_date) | symbol | name| +-++-+ | 2004-10-05 |

Re: simple but frustrating query

2004-10-14 Thread SGreen
It takes two steps: first determine the max(closedate) for each symbol, then use those results to get the name field. You could do this with a subquery (both steps in the one statement) because you are using a version of MySQL 4.0.0 but here is a temp table implementation that will work with

Re: simple but frustrating query

2004-10-14 Thread Joe Audette
+-++-+ | max(close_date) | symbol | name| +-++-+ | 2004-10-05 | aa | cmptrhw | | 2004-10-05 | bb | biotech | | 2004-10-05 | cc | biotech |

Re: simple but frustrating query

2004-10-14 Thread Jeff Mathis
we really don't want to issue two queries. this should be able to be done in one, and without using temp tables, but maybe not. thanks for the help though jeff [EMAIL PROTECTED] wrote: It takes two steps: first determine the max(closedate) for each symbol, then use those results to get the name

Re: simple but frustrating query

2004-10-14 Thread Brad Eacker
Jeff Mathis writes: now, leaving off name from the group by clause (select max(close_date), symbol, name from TD where symbol in ('aa','bb','cc') group by symbol;) gives +-++-+ | max(close_date) | symbol | name|

Re: simple but frustrating query

2004-10-14 Thread Michael Stassen
No, Shawn's answer is correct. You are starting from a false assumption. You are expecting that MAX(closedate) corresponds to a row. It does not. Consider the table Table=stuff: sym val note --- --- AAA 2 one AAA 2 two AAA 4 three AAA 6 four AAA 12 five

Re: simple but frustrating query

2004-10-14 Thread Jeff Mathis
4.1.3 and the innodb engine on solaris 5.8 Brad Eacker wrote: Jeff Mathis writes: now, leaving off name from the group by clause (select max(close_date), symbol, name from TD where symbol in ('aa','bb','cc') group by symbol;) gives +-++-+ | max(close_date) |

Re: simple but frustrating query

2004-10-14 Thread Jeff Mathis
well, obviously some, if not all, of what you are saying is true. your table example below though is not the same as mine. My table stores time series data. for every symbol, there are a series of rows all with different dates. there is a unique constraint on the combination of symbol and

Re: simple but frustrating query

2004-10-14 Thread Michael Stassen
Jeff Mathis wrote: well, obviously some, if not all, of what you are saying is true. your I don't believe I said anything untrue. Did you have something in mind? table example below though is not the same as mine. My table stores time series data. for every symbol, there are a series of rows