SQL INNER JOIN


The most frequently used and important of the joins is the SQL INNER JOIN.

The SQL INNER JOIN clause selects all records or rows from both tables (tableA and tableB) and returns a result table by combining field or column values of two tables that is limited to the records as long as where there is a match keys in both tables.


Search Keys

  • sql inner join
  • sql update inner join
  • inner join 3 tables
  • multiple inner joins
  • inner join example
  • select inner join
  • inner join syntax
  • left inner join
  • inner join where
  • query inner join
  • sql inner join three tables
  • sql delete from inner join
  • left join inner join
  • outer inner join
  • right inner join
  • inner join 2 tables
  • inner join on multiple tables
  • inner join multiple tables
  • inner join sql example
  • select from inner join

SQL INNER JOIN Syntax

Syntax for Inner Join is as


SELECT column_name1, column_name2, ...column_nameN
FROM table_name1
INNER JOIN table_name2
ON table1.column_name1 = table2.column_name1;

or

SELECT column_name1, column_name2, ...column_nameN
FROM table_name1
JOIN table_name2
ON table1.column_name1 = table2.column_name1;

Note: INNER JOIN is the same as JOIN.

SQL INNER JOIN


Sample Database Table - Books

BookId BookName BookPrice RelYear DomainName AuthorName
1 The Complete Guide to MySql 120 2014 Optimization Dharan
2 Securing Oracle 165 2013 Administration Balan
3 Database Systems Using Oracle 178.69 2015 Performance Nirmala
4 Advanced SQL Programming 105 2006 Security Azaghu Varshith
5 Microsoft SQL Server 2012 Bible 199.97 2015 Security Vinoth Kumar
6 Professional Microsoft SQL Server 170 2014 Security Ranjani Mai
7 SQL for students 75 2012 Security Dharan
8 MySql Query Performance Tuning 95 2013 Administration Bala Murugan
9 Natural language Query To SQL 190 2014 Programming Ranjani Mai
10 SQL Pocket Guide 160 2015 Security Siva Kumar
12 PHP And MySQL Bible 90 2010 Performance Rishi Keshan

Sample Database Table - BookOrder

BookID OrderDate Qty DeliveryDate
1 15-04-2011 2 17-05-2011
2 15-05-2000 16 24-05-2000
3 22-05-1995 18 25-05-1995
4 16-08-2004 16 20-08-2004
5 16-02-2001 19 20-02-2001
6 24-06-2002 9 26-07-2002
7 24-08-2001 12 27-08-2001
8 25-01-1995 2 27-01-1995
9 17-09-1997 17 25-10-1997
10 20-08-2005 9 27-09-2005
11 11-06-1995 8 26-07-1995

Note:- There must be a common columns while selecting columns from multiple tables. In the "BookOrder" and "Books" both tables contains a common column called "ID".


SQL INNER JOIN - Example

Notice that the "BookID" column in the "Books" table refers to the "ID" in the "BookOrder" table. The relationship between the two tables above is the "BookID" column.

Then, if we run the following SQL statement (that contains an INNER JOIN):


SELECT 
Books.BookID, Books.BookName, BookOrder.Qty, BookOrder.OrderDate
FROM Books
INNER JOIN BookOrder
ON Books.BookID = BookOrder.BookID;

The result of above query is:

BookID BookName Qty OrderDate
1 The Complete Guide to MySql 2 15-04-2011
2 Securing Oracle 16 15-05-2000
3 Database Systems Using Oracle 18 22-05-1995
4 Advanced SQL Programming 16 16-08-2004
5 Microsoft SQL Server 2012 Bible 19 16-02-2001
6 Professional Microsoft SQL Server 9 24-06-2002
7 SQL for students 12 24-08-2001
8 MySql Query Performance Tuning 2 25-01-1995
9 Natural language Query To SQL 17 17-09-1997
10 SQL Pocket Guide 9 20-08-2005

Note: If there are rows in the "Books" table that do not have matches in "BookOrder", these Books will NOT be listed.


Search Keys

  • sql command inner join
  • sql 2 inner joins
  • 3 table inner join
  • sql statement inner join
  • inner join explained
  • inner join with where condition
  • sql query for inner join
  • sql inner join order by
  • sql multiple inner join example
  • inner join database
  • sql inner join and outer join
  • sql inner join performance
  • sql joins with examples
  • joins in sql with examples
  • sql multiple joins
  • sql tutorial joins
  • sql join multiple tables
  • left outer join multiple tables
  • join multiple tables sql
  • sql left join multiple tables