我有三张桌子。
地点
ID | NAME | TYPE |
1 | add1 | stat |
2 | add2 | coun |
3 | add3 | coun |
4 | add4 | coun |
5 | add5 | stat |
学校
ID | NAME
1 | sch1
2 | sch2
3 |sch3
school_locations
ID |LOCATIONS_ID |SCHOOL_ID
1 | 1 |1
2 | 2 |2
3 | 3 |3
这里的位置表包含应用程序的所有位置。学校的位置由 ID 调用。
当我使用查询时
select locations.name from locations where type="coun";
它显示类型为“coun”的名称
但我想显示只有 school_locations 有 type="coun" 的位置。
我尝试了以下查询,但似乎没有一个有效
select locations.name
from locations
where type="coun"
inner join school_locations
on locations.id=school_locations.location_id
inner join schools
on school_locations.school.id=schools.id;
和
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";
是否可以在查询中使用多个内部联接,还是有其他方法?