How to Join 3 Tables—Without Join Keyword

Here’s SQL query to join three tables and fetch data from two table without using join keyword.

Joining Tables with WHERE clause

Here are three tables used in join query

  1. mystudent_table
  2. mycourse_table
  3. mystudent_course_table

Here’s SQL query to join multi tables

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

The three tables

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


Join 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.