简体   繁体   中英

SQL queries on result table

I have 3 tables ( Instructors , Instructors_config and Teach ) :

Instructors

instructor_id | first_name | last_name | email | password | status

Instructors_config

instructor_id | profile_pic | fb | twitter | info

Teach

instructor_id | course_id

Where Teach contain what courses each instructor teach , each instructor can teach multiple courses and each course can be taught by many instructors (many to many relationship ) .

i want to write a function which receive course_id and return all instructors who teach this course along with their fist_name and last_name from Instructors Table along with their info from Instructor_config table , currently i am using the following query to do that and it works fine :

SELECT instructors.in_id, instructors_config.info, instructors.first_name, instructors.last_name 
FROM instructors 
INNER JOIN instructors_config ON instructors.in_id = instructors_config.in_id 
INNER JOIN teach ON teach.in_id=instructors_config.in_id AND teach.cs_id='.$id

but is their a better or faster way to achieve that or this one is good enough ?

Query looks fine but please make sure all below column are indexed properly

instructors.in_id,
instructors_config.in_id ,
teach.in_id and 
teach.cs_id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM