2009-09-03 10 views
0

こんにちは注文して、MySQL上で動作していないことで注文、<strong><em>のMySQL</em></strong></p> <p>コードは以下のとおりであるに取り組んでいない

select * from School where School.type = 'HighSchool' 
    order by (select locations.name from locations inner join School_locations 
     on locations.id = School_locations.location_id where 
     School_locations.School_id = School.id and locations.location_country = 'US' limit 1) 

と出力は両方が同様に昇順に同じ表示していますこの問題を解決する方法を降順にする

答えて

2

サブクエリを実行する必要はありません:

SELECT s.* 
FROM School s 
    INNER JOIN School_locations sl ON (s.id = sl.School_id) 
    INNER JOIN locations l ON (l.id = sl.location_id) 
WHERE l.location_country = 'US' AND s.type = 'High school' 
ORDER BY l.name 
+0

1このクエリを使用することができ、この方法が良いです。 –

+0

おかげでBudの+1がうまくいく –

0
select school.* from school 
    inner join school_locations on school_locations.schoolid = school.school_id 
    inner join locations on locations.location.id = school_locations.locationid 
where 
    locations.location_country = 'US' and school.type = 'HighSchool' 
order by 
    locations.name 
limit 1 
0

あなたは

select School.* from School inner join School_locations 
on School_locations.School_id = School.id 
inner join locations 
on locations.id = School_locations.location_id 
where locations.location_country = 'US' and School.type = 'HighSchool' 
order by locations.name limit 1 
関連する問題