Joining Tables with JOIN Clauses in Database

Joining Tables with JOIN Clauses in Database

Date posted: 02/05/2019

Join clause:

The SQL Join clause is used to combine records from two or more tables in a database.

A JOIN means for combining fields from two tables by using
common values to each.

Different types of joins

  1. INNER JOIN – selects records that have matching values in both tables.
  2. LEFT JOIN− selects all rows from the left table, even if there are no matches in the right table.
  3. RIGHT JOIN– selects all rows from the right table, even if there are no matches in the left table.

Pre-requesties

we have to create database and table. Firstly, create database and name it as ‘join test’. Then use the database.

Similarly, create a tables ‘s_table1 ‘ with column name ‘s_id’ and ‘s_name’.

Similarly in the vein, create a tables ‘s_table2 ‘ with column name ‘s_id’ and ‘s_city’.


‘s_table1 ‘ and ‘s_table2’ data:

INNER JOIN :

MariaDB [jointest]> select s_table1.s_id,s_table1.s_name,s_table2.s_id,s_table2.s_city from s_table1 inner join s_table2 on s_table1.s_id=s_table2.s_id;

LEFT JOIN

MariaDB [jointest]> select s_table1.s_id,s_table1.s_name,s_table2.s_id,s_table2.s_city from s_table1 left join s_table2 on s_table1.s_id=s_table2.s_id;

RIGHT JOIN

MariaDB [jointest]> select s_table1.s_id,s_table1.s_name,s_table2.s_id,s_table2.s_city from s_table1 right join s_table2 on s_table1.s_id=s_table2.s_id;

Thanks for using pheonix solutions.

You find this tutorial helpful? Share with your friends to keep it alive

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Reply

Scroll to Top