SQL INNER JOIN Keyword
The INNER JOIN keyword returns only the rows that have matching values in both tables involved in the join. It is commonly used to combine rows from two tables based on a related column.
SQL INNER JOIN Syntax
SELECT column_names FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
SQL INNER JOIN Appointments with Doctors Example
This query displays appointment IDs and the corresponding doctor’s last name by matching doctor_id.
SELECT Appointments.appointment_id, Doctors.last_name FROM Appointments INNER JOIN Doctors ON Appointments.doctor_id = Doctors.doctor_id;

SQL INNER JOIN Appointments with Patients Example
This query displays the appointment ID and patient’s first name for each appointment.
SELECT Appointments.appointment_id, Patients.first_name FROM Appointments INNER JOIN Patients ON Appointments.patient_id = Patients.patient_id;

SQL INNER JOIN Prescriptions with Appointments and Doctors Example
This query displays prescriptions with related doctor and appointment information.
SELECT Prescriptions.medication_name, Doctors.last_name, Appointments.appointment_date FROM Prescriptions INNER JOIN Appointments ON Prescriptions.appointment_id = Appointments.appointment_id INNER JOIN Doctors ON Appointments.doctor_id = Doctors.doctor_id;
