SQL INNER JOIN Keyword

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.

Comments

sir magkano pagawa ng payroll system using vb,asp.net sql? hirs my number sir 09228590639.

Add new comment