deedub84
asked on
SQL Join Issue
In MySQL I'm working with a database table called Events I didn't design and can't change which has a field EventTime which is a varchar(8) which has entries like '9:00 AM', '11:00 AM', '3:00 PM'. The table only has entries for certain times during the day.
I need to create a report for a particular day (in essence a day calendar) which lists all the times in ascending order whether or not they have corresponding records in the Events table, but if there is one it should show up.
Ex:
9:00 AM Event1
10:00 AM
11:00 AM Event2
12:00 PM
1:00 PM
2:00 PM Event3
...
6:00 PM
I have created a table TimeOrder with the various text fields of time with an ID field so that I can order properly:
ID TimeValue
1 9:00 AM
2 10:00 AM
3 11:00 AM etc
I'm trying to create a left join statement so that I see all the records in TimeOrder (i.e. the full day with all timeslots) with matching records from the Events table when there are any. Here's my SQL Statement
However my output only has the timeslots with corresponding records in Event (similar to an inner join).
Any thoughts?
I need to create a report for a particular day (in essence a day calendar) which lists all the times in ascending order whether or not they have corresponding records in the Events table, but if there is one it should show up.
Ex:
9:00 AM Event1
10:00 AM
11:00 AM Event2
12:00 PM
1:00 PM
2:00 PM Event3
...
6:00 PM
I have created a table TimeOrder with the various text fields of time with an ID field so that I can order properly:
ID TimeValue
1 9:00 AM
2 10:00 AM
3 11:00 AM etc
I'm trying to create a left join statement so that I see all the records in TimeOrder (i.e. the full day with all timeslots) with matching records from the Events table when there are any. Here's my SQL Statement
SELECT e.Date, t.TimeValue, e.EventType, trim(e.FName) + trim(e.LName), e.AttCount
FROM TimeOrder t
Inner JOIN enrolled e on t.timevalue = e.eventtime
WHERE e.Date = '2013-01-01'
ORDER BY t.ID
However my output only has the timeslots with corresponding records in Event (similar to an inner join).
Any thoughts?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
However, your subquery solution did the trick. Thanks!