この投稿では:データを取得するための SQL クエリ.
最初の答えは次のとおりです。
SELECT students.student_id,student_name,father_name,mother_name,
COUNT(student_addresses.student_id) AS total_addresses,
COUNT(student_phones.student_id) AS total_phones
FROM students,student_phones,student_addresses
WHERE students.student_id = student_phones.student_id AND
students.student_id = student_addresses.student_id AND
students.student_id = 7
GROUP BY BY students.student_id,student_name,father_name,mother_name;
2番目は次のとおりです。
SELECT s.student_id,
max(s.student_name) student_name,
max(s.father_name) father_name,
max(s.mother_name) mother_name,
COUNT(distinct a.student_address_id) total_addresses,
COUNT(distinct p.student_phone_id) total_phones
FROM students s
LEFT JOIN student_phones p ON s.student_id = p.student_id
LEFT JOIN student_addresses a ON s.student_id = a.student_id
WHERE s.student_id = 7
GROUP BY s.student_id
さて、質問: パフォーマンスに関して、2 つのクエリに大きな違いはありますか? の使用はMAX()
2 番目のクエリの実行時間に影響しますか?
答えをグーグルで検索しようとしましたが、うまくいきません。これについては、明確で具体的な説明が必要です。