I am trying to get a query out of two tables. This should be straightforward; however, my results duplicate. I can not use DISTINCT or GROUP BY since there is not a unique ID. For testing, my primary table has 87 rows. With no WHERE identified I get 174 results. My two tables are as follows:
table - lifegroups_attendance (date is a date field, time is a varchar)
No unique ID - a combo of date/time/group would be closest to it
date | time | group| attendance
--------------------------------
1/3/15 | 6:30 PM | Adults | 125
1/3/15 | 11:00 AM | Adults | 621
1/4/15 | Saturday | Kids | 289
1/4/15 | Sun PM | Adults | 621
table - sat_week_date_map (the start of the week is Saturday instead of MySQL built in Sun or Mon option)
Date is the primary ID
date | week
---------------
1/3/15 | 1
1/4/15 | 1
1/5/15 | 1
1/10/15 | 2
I need to get a result that looks like this:
week | group | attendance
1 | adults | 125
1 | adults | 621
1 | adults | 621 (This is not a duplicate - date/time is different)
2 | adults | 475
2 | adults | 276
2 | kids | 289
Instead I'm getting
week | group | attendance
1 | adults | 125
1 | adults | 621
1 | adults | 621 (This is not a duplicate - date/time is different)
2 | adults | 475
2 | adults | 276
2 | kids | 289
1 | adults | 125 (repeats every record over again)
1 | adults | 621
1 | adults | 621 (This is not a duplicate - date/time is different)
2 | adults | 475
2 | adults | 276
2 | kids | 289
The query I'm currently using is:
SELECT wd.week, la.group AS group, la.attendance
FROM sat_week_date_map AS wd JOIN lifegroups_attendance AS la
ON la.date = wd.date;
week, date, attendandance, why does your sample result haveweek, group, attendance?125or621in the input.1 adults 621is not a duplicate because the time is different. But shouldn't the attendance column be different at the different times, like in yourlifegroups_attendancetable?