Code has been added to clipboard!

How to Combine Table Rows Using SQL JOIN

Reading time 1 min
Published Aug 11, 2017
Updated Oct 3, 2019

SQL Joins: Main Tips

  • SQL joins are used to combine more than one tables rows.
  • SQL INNER JOIN is the most common JOIN. An SQL INNER JOIN returns all multiple tables rows where the join condition is met.

SQL Join: Types

  • LEFT JOIN: It returns the left table rows and right table rows which matched.
  • RIGHT JOIN: It returns the right table rows, and left table rows which matched.
  • INNER JOIN: It returns all rows when there is the same record in BOTH tables.
  • FULL OUTER JOIN: It returns all rows when the same record occurs in BOTH tables.

Demo Database

This is a demo example from the "Orders" table in the database:

ID Customer_ID Employee_ID
20408 2 7
20409 2 5
85471 1 3
75864 5 8

This is a demo example from the "Developers" table in the database:

ID Name City Country
1 Tom Kurkutis New York USA
2 Ana Fernandez London UK
3 Antonio Indigo Paris France
4 Aarav Kaelin Delhi India
5 Andrew Tumota Miami USA

INNER JOIN: Example

Example
SELECT Customer_orders.ID, Developers.Name
FROM Customer_orders
INNER JOIN Developers ON Customer_orders.employee_id = Developers.ID;

The result table looks like this:

ID Name Date
1509 Tom Kurkutis 8/18/2017
1510 Andrew Tumota 12/19/2016
1511 Andrew Tumota 01/25/2017
Learn SQL
Introduction
Syntax
Data Types
Server Data Types
Commands
Commands List
Wildcards
Constraints
Aggregate Functions
Date Functions
Date Format
Injection
SQL Server Hosting
Views
Auto-incrementation
SQL Operators
AS
AND & OR
IN
BETWEEN
WHERE
GROUP BY
HAVING
ORDER BY
LIKE
NOT
NOT EQUAL
UNION
NULL
NOT NULL
DEFAULT
UNIQUE
FOREIGN KEY
PRIMARY KEY
CHECK
Indexes
ALTER TABLE
CREATE DATABASE
CREATE TABLE
DELETE
DROP
INSERT INTO SELECT
INSERT INTO
SELECT
SELECT DISTINCT
SELECT INTO
SELECT TOP
UPDATE
FULL OUTER JOIN
INNER JOIN
JOIN
LEFT JOIN
RIGHT JOIN
AVG()
COUNT
FIRST
LAST
MAX
MIN()
SUM()
LEN
UCASE
MID
NOW
ROUND
FORMAT
LOWER
CONVERT
ISNULL