SQL Inner Join

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

SELECT columns
FROM left_table
INNER JOIN right_table
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.

SELECT a.appointment_date AS "Appointment Date", pr.medication_name AS "Medication Name"
FROM Appointments AS a
INNER JOIN Prescriptions AS pr
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.

SELECT p.first_name AS "Patient Name", m.record_date AS "Record Date", m.description AS "Description"
FROM Patients AS p
INNER JOIN MedicalRecords AS m
ON p.patient_id = m.patient_id;




SQL Inner Join Visual Diagram




SQL Inner Join Labs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top