Re: Daily SQL Quiz
Posted in 1993
Topics: General Discussion
In article <1993May05.054053.2915@wvus.org> sford@wvus.org (Scott Ford) writes:
>And now for today's SQL pop quiz:
>
>Suppose we have a table that contains a composite primary key on columns
>task_id and instance_date.
>
>Now suppose that the table is populated with lots of data and we want to
>get a listing of all tasks of a certain type, but only the latest date
>for each type. Easy, right?
>
>Now suppose there's another column in the table that we want to select.
>If it has differing values, we have a problem. This is because we'll get
>a row back for every differnt value in that other column.
>
>If we are obstinate and refuse to use a programming language (other than
>SQL) or a temporary table, can we still get the result we want?
(I'm no expert, but) I believe that SQL allows recursive queries.
Therefore, what you want would look like this (in pseudo-code):
select * from Task where task_id = (select task_id from Task where
max(instance_date))
--
--- Aahz
Hugs and backrubs -- I break Rule 6
Kinky vanilla queer het
I'm not a jerk, but I play one on the Net.