I have the following query:
select distinct t1.email, t1.adate, t1.site, t1.grpID, t1.hs_uid, t3.adate, t3.site, t3.bDay, t3.bMonth, t3.hs_uid, t3.Personal_Sex, t3.last_name, t3.first_name from hs_userdata as t1 join (SELECT hs_uid, adate, site, bDay, bMonth, hs_uid, Personal_Sex, last_name, first_name from hs_hradata AS t3 where adate>='2006-02-01 00:00:00' AND adate<='2006-02-20 23:59:59' union select hs_uid, adate, site, bDay, bMonth, hs_uid, Personal_Sex, last_name, first_name from hs_ghadata AS t3 where adate>='2006-02-01 00:00:00' AND adate<='2006-02-20 23:59:59' union select hs_uid, adate, site, bDay, bMonth, hs_uid, Personal_Sex, last_name, first_name from hs_crcdata AS t3 where adate>='2006-02-01 00:00:00' AND adate<='2006-02-20 23:59:59' union select hs_uid, adate, site, bDay, bMonth, hs_uid, Personal_Sex, last_name, first_name from hs_drcdata AS t3 where adate>='2006-02-01 00:00:00' AND adate<='2006-02-20 23:59:59' union select hs_uid, adate, site, bDay, bMonth, hs_uid, Personal_Sex, last_name, first_name from hs_fitdata AS t3 where adate>='2006-02-01 00:00:00' AND adate<='2006-02-20 23:59:59' union select hs_uid, adate, site, bDay, bMonth, hs_uid, Personal_Sex, last_name, first_name from hs_gwbdata AS t3 where adate>='2006-02-01 00:00:00' AND adate<='2006-02-20 23:59:59')as t3 on t3.hs_uid = t1.hs_uid order by t1.grpID
Which shows me all the records created between certain dates within a group of tables. What I need is only one record per hs_uid, so if they have a record in the hs_gwbdata table, I don't need to know that they also have one in hs_crcdata table and so on. The adate is a time stamp so records from the different tables will have different adates. Is what I am asking for possible within a SQL statement or will I need to post process my list?
Start Free Trial