[thelist] MySQL Query problem: unique vals from two fields

Matt Warden mwarden at gmail.com
Wed Nov 22 10:50:01 CST 2006


On 11/22/06, Pringle, Ron <RPringle at aurora-il.org> wrote:
> SELECT DISTINCT(Year(exEndDate)) as exhibitYear FROM tbl_exhibitDates WHERE exEndDate < CURRENT_DATE() ORDER BY exhibitYear ASC;
>
>
> Ideas, blows to the head with blunt objects, etc. much appreciated.

Fresh out of blunt objects, but maybe I can help with the query.

select distinct year(exEndDate) as exhibitYear
from tbl_exhibitDates
where exEndDate < current_date()
union
select distinct year(exStartDate)
from tbl_exhibitdates
where exStartDate < current_date()

This *should* return only distinct years, because it is union and not
union all. However, give it a try in your DB of choice and if it is
duping years that exist in both sets, we will have to filter those out
in the where clause of the second query.

HTH,

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list