มณฑล พร้อมสันเทียะ
วันที่โพสต์: Dec 05, 2018 7:21:1 AM
Here are the different types of the JOINs in SQL:
(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the right table
RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from the left table
FULL (OUTER) JOIN: Return all records when there is a match in either left or right table
SELECT permission_main.id
FROM
permission_main LEFT JOIN permission_follower
ON permission_main.ref_id=permission_follower.ref_id
WHERE
(permission_main.person_id='$user'
or permission_follower.person_id='$user')
group by permission_main.id
เริ่มการ "ดึงข้อมูล" LEFT JOIN ใหม่
ด้วยการสร้างดัชนี (index) เสียใหม่ทำให้คลอบคลุมสิ่งที่เราต้องการค้นหา ช่วยให้การประมวลผลความเร็วเพิ่มขึ้นกว่า 5 เท่า
จากเดิม
permission_main index = id, ref_id
permission_follower index = id, ref_id
เป็น
Run SQL ใน AMSS++
ALTER TABLE permission_main ADD INDEX(ref_id);
ALTER TABLE permission_main ADD INDEX(person_id);
ALTER TABLE permission_follower ADD INDEX(ref_id);
ALTER TABLE permission_follower ADD INDEX(person_id);