Trying to mash together results from two tables: EventTemplates, and UserEvents.
EventTemplates is just full of data about an event - date, title etc. When a user participates in an event, my PHP application pulls the required record out of EventTemplates and drops it into a form. The user is then free to edit all or some of these fields. When they submit the form, all that data is dropped into UserEvents, along with their userID.
So UserEvents is just a clone of EventTemplates, with a UserID field.
For a calendar feature, I want to pull out everything from EventTemplates, coupled with everything for that user from UserEvents.
Trouble is, when I do that I get duplicate rows.
This is what I've done:
Code:
SELECT
idUserEvents,
eventName,
idEventTemplates
FROM
UserEvents
WHERE idUsers = 19
UNION
SELECT
idEventTemplates
eventName,
idEventTemplates
FROM
EventTemplates
I need to get that
idUserEvents field out of UserEvents, and I need to get that
idEventTemplates field out of
EventTemplates.
But if a user's added an event using that event template, then I get two rows back for it; one from each table. The UNION doesn't see them as distinct because it's comparing the id's from two different tables.
Am I going about this all wrong?