The SQL Inner Join is used to combine rows from two or more tables based on a related column between them. It only returns the rows where there is a match in both tables.
SQL Inner Join Syntax
SQL
x
1
SELECT columns
2
FROM left_table
3
INNER JOIN right_table
4
ON left_table.common_column = right_table.common_column;
SQL Inner Join Finding Prescriptions Linked to Appointments Example
This query retrieves patients and their prescribed medications. It will only display patients who have been given a presciption.
SQL
1
1
SELECT a.appointment_date AS "Appointment Date", pr.medication_name AS "Medication Name"
2
FROM Appointments AS a
3
INNER JOIN Prescriptions AS pr
4
ON a.appointment_id = pr.appointment_id;

SQL Inner Join Retrieving Patients with Their Medical Records Example
This query retrieves patient names along with the dates and descriptions of their medical records.
SQL
1
1
SELECT p.first_name AS "Patient Name", m.record_date AS "Record Date", m.description AS "Description"
2
FROM Patients AS p
3
INNER JOIN MedicalRecords AS m
4
ON p.patient_id = m.patient_id;
