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
SQL
x
1
SELECT column_names
2
FROM table1
3
INNER JOIN table2
4
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.
SQL
1
1
SELECT Appointments.appointment_id, Doctors.last_name
2
FROM Appointments
3
INNER JOIN Doctors
4
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.
SQL
1
1
SELECT Appointments.appointment_id, Patients.first_name
2
FROM Appointments
3
INNER JOIN Patients
4
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.
SQL
1
1
SELECT Prescriptions.medication_name, Doctors.last_name, Appointments.appointment_date
2
FROM Prescriptions
3
INNER JOIN Appointments ON Prescriptions.appointment_id = Appointments.appointment_id
4
INNER JOIN Doctors ON Appointments.doctor_id = Doctors.doctor_id;
