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

SQL Joins

theguywhodoesntleach

Rogue Agent
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
98
Likes
119
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
SQL JOIN is used to combine two or more tables based on primary key and foreign keys.

We use Join in conjunction with the table we normalize during database design. Consider a Department table we have in our previous example. We create a Department table that serves as our master file to be called from other table.

SQL JOIN can be very time consuming on large table, e.g. one with millions of records, since it has to match each row of one table, and check it with each row of other tables mentioned in the JOIN keyword.

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

Please don't be confused with the previous table that we have used before. In the above example we have DeptID in the Users table and we also have DeptID in the Departments table. DeptID in the Departments table is the Primary key and DeptID in the Users table is the Foreign key. We can use those keys to create a join. They are responsible for combine two or more tables in our database.

 

452,292

323,526

323,535

Top