Join Three Tables with WHERE Here is Useful SQL Query

Here is an SQL query to join three tables using WHERE clause (Without JOIN Keyword). Here you can use the third table for joining purposes, but you fetch data from two tables.

Joining Tables with WHERE clause

Here are the tables I Would use

  1. mystudent_table
  2. mycourse_table
  3. mystudent_course_table

Join Three Tables Method

SQL Query to Join Three Tables using WHERE
SQL Query to Join Three Tables using WHERE

Before Join The Columns in Three Tables as Below

1. Columns in mystudent_table


Here is an article on LEFT Vs RIGHT Join and which is better.

2. Columns in mycourse_table


Here is blog post on How to use LEFT and RIGHT functions to get Substring.

3. Columns in mystudent_course_table


SQL Query

SELECT ALL Columns from the mycourse_table and mystudent_table and Join them. In the first WHERE condition, you can see the equi join on student id. The next condition, is on course id. The result is you will all the rows from two tables (S* and C*).

select s*, c*
from mystudent_table s
mycourse_table c
mystudent_course_table sc
where s.student_id = sc.student_id
and c.course_id = sc.course_id;

The purpose of mystudent_course_table is just a bridge between these two tables.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.