deepatpaul
Programmer
This query was returning all events based on the following parameters. An additional condition was required, and that was to retrieve all teachers based on the event.
Now, some events may not have teachers, but my added SQL clause doesn't return events if no teachers are associated to it.
Old one:
SELECT DISTINCT mos_events.*
FROM mos_categories AS b, mos_events
LEFT JOIN mos_events_users AS user ON (user.eventID=mos_events.id)
WHERE mos_events.catid = b.id AND b.access <= 0 AND mos_events.access <= 0
AND (
AND mos_events.state = '1'
)
ORDER BY reccurtype ASC,publish_up ASC
New one:
SELECT DISTINCT mos_events.*, teacher.name
FROM mos_categories AS b, mos_events, mos_teacher AS teacher
LEFT JOIN mos_events_users AS user ON (user.eventID=mos_events.id)
WHERE mos_events.catid = b.id AND b.access <= 0 AND mos_events.access <= 0
AND (
AND mos_events.state = '1'
AND (user.userID = teacher.id)
)
ORDER BY reccurtype ASC,publish_up ASC
Is there any additional nesting, or using an OR, that could make not have a user and teacher relation be mandatory to return records?
Now, some events may not have teachers, but my added SQL clause doesn't return events if no teachers are associated to it.
Old one:
SELECT DISTINCT mos_events.*
FROM mos_categories AS b, mos_events
LEFT JOIN mos_events_users AS user ON (user.eventID=mos_events.id)
WHERE mos_events.catid = b.id AND b.access <= 0 AND mos_events.access <= 0
AND (
AND mos_events.state = '1'
)
ORDER BY reccurtype ASC,publish_up ASC
New one:
SELECT DISTINCT mos_events.*, teacher.name
FROM mos_categories AS b, mos_events, mos_teacher AS teacher
LEFT JOIN mos_events_users AS user ON (user.eventID=mos_events.id)
WHERE mos_events.catid = b.id AND b.access <= 0 AND mos_events.access <= 0
AND (
AND mos_events.state = '1'
AND (user.userID = teacher.id)
)
ORDER BY reccurtype ASC,publish_up ASC
Is there any additional nesting, or using an OR, that could make not have a user and teacher relation be mandatory to return records?