MySQL Forums
Forum List  »  Newbie

Is JOIN what I need?
Posted by: robophobic
Date: August 08, 2005 08:51PM

I'm trying to write a query that *should* be simple, but I'm having quite a bit of difficulty with it. I have two tables, one is College and the other Locations.
I need to pull up a list of all schools in the College table that also have an entry in the Locations table. Here's the query I used:
SELECT college.id , college.name , sitting_msg , schooltype FROM college, location WHERE college.schooltype LIKE 'yearbook' AND location.college_id = college.id;

The problem is that there are multiple entries for some colleges in the Locations table, and this query lists the college each time an entry is found in the Locations table. (i.e. Loyola U. has 3 locations, Gym, Library, Cafeteria, so the query result lists Loyola U. 3 times)
Any idea how to get the query to just list each college once if it has multiple rows in the locations table while not listing it at all if there are no entries?

Options: ReplyQuote


Subject
Written By
Posted
Is JOIN what I need?
August 08, 2005 08:51PM
August 09, 2005 01:06AM
August 09, 2005 08:12AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.