• We just launched and are currently in beta. Join us as we build and grow the community.

SQL INNER JOIN Keyword

flareclare100

Anime News Reporter
F Rep
0
0
0
Rep
0
F Vouches
0
0
0
Vouches
0
Posts
96
Likes
47
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
SQL INNER JOIN is almost the same as the normal join. But the INNER JOIN will only list those rows which have
at least one matching value from both tables.

SQL INNER JOIN Syntax

SELECT

column_name(

s)

FROM

First_table_name INNER

JOIN

Second_table_name ON

First_table_name.

column_name=

Second_table_name.

column_name

Consider the following table for this exercise

Users

Firstname

Lastname

Salary

DeptID

John

Smith

1000

1

Mathew

Simon

3000

1

Bill

Steve

2200

1

Amanda

Rogers

1800

2

Steve

Hills

2800

2

Steve

jobs

2400

2

bill

cosby

700

3

Departments

DeptID

DepartmentName

1

Employee

2

Management

3

Staff

Example # 1

SELECT

Firstname,

Lastname,

Salary,

DepartmentName FROM

Users INNER

JOIN

Departments ON

Users.

DeptID =

Departments.

DeptID

Result of the Query

Firstname

Lastname

Salary

DepartmentName

John

Smith

1000

Employee

Mathew

Simon

3000

Employee

Bill

Steve

2200

Employee

Amanda

Rogers

1800

Management

Steve

Hills

2800

Management

Steve

jobs

2400

Management

bill

cosby

700

Staff

We have joined the two tables and matching the primary keys and the foriegn keys from both tables. But of course the column name is not bound to primary keys and foreign. You could link other column as well.

 

452,292

323,340

323,349

Top