using where and inner join in mysql using where and inner join in mysql mysql mysql

using where and inner join in mysql


    SELECT `locations`.`name`      FROM `locations`INNER JOIN `school_locations`        ON `locations`.`id` = `school_locations`.`location_id`INNER JOIN `schools`        ON `school_locations`.`school_id` = `schools_id`     WHERE `type` = 'coun';

the WHERE clause has to be at the end of the statement


Try this:

SELECT Locations.Name, Schools.NameFROM LocationsINNER JOIN School_Locations ON School_Locations.Locations_Id = Locations.IdINNER JOIN Schools ON School.Id = Schools_Locations.School_IdWHERE Locations.Type = "coun"

You can join Locations to School_Locations and then School_Locations to School. This forms a set of all related Locations and Schools, which you can then widdle down using the WHERE clause to those whose Location is of type "coun."


Try this :

SELECT    (      SELECT          `NAME`      FROM          locations      WHERE          ID = school_locations.LOCATION_ID    ) as `NAME`FROM     school_locationsWHERE     (      SELECT          `TYPE`      FROM          locations      WHERE          ID = school_locations.LOCATION_ID     ) = 'coun';