Rick Ratchford wrote:
> Okay, this worked, but I have NO IDEA why.
>
>    SQLString = "SELECT min(Year) FROM TmpTable " & _
>                "WHERE Month=1 UNION " & _
>                "SELECT max(Year) FROM TmpTable " & _
>                "WHERE Month = 12 LIMIT 2"

Read about aggregate functions (min() is one of those) in your favorite SQL
textbook, then drop the LIMIT clause. You may also want to use UNION ALL
instead of UNION: otherwise, if you just have one full year's worth of data,
you'll get a single row as UNION removes duplicates.

In fact, it may be more convenient (definitely easier to reuse as a fragment
in more complicated queries) to return this result as one row with two
columns:

select
    (select min(Year) ...) as firstFullYear,
    (select max(Year) ...) as lastFullYear;

Igor Tandetnik 

----------------------------------------

Igor,

If I go with the condensed version you illustrate above, I assume that I
would then need to use the LIMIT clause, right? When I tried it, I get a
bunch of rows returned, all with the same information.

1988  2008
1988  2008
1988  2008
1988  2008
1988  2008
1988  2008
...

Here is the SQL used:

Select (Select min(Year) From TmpTable Where Month=1 and Day<8) as
FirstYear,
       (Select max(Year) From TmpTable Where Month=12 and Day>24) as
LastYear FROM TmpTable"


LIMIT 1 ??

Thanks.
Rick



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to