Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query not returning expected records

Status
Not open for further replies.

deepatpaul

Programmer
Jul 7, 2004
57
0
0
US
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?
 
UPDATE

I'm getting the proper return of values here, but if any event has more than 1 teacher associated, it displays it multiple times (n teachers = n displays).

SELECT DISTINCT mos_events.*, teacher.name FROM mos_categories AS b, mos_events
LEFT JOIN mos_events_users AS user ON (user.eventID=mos_events.id)
LEFT JOIN mos_users AS teacher ON (user.userID = teacher.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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top