Home     SQL Basic     MYSQL Basic     Contact Us     Site Map    

SQL BASIC

SQL SELECT

SQL WHERE

SQL DISTINCT

SQL AND

SQL OR

SQL NOT

SQL ORDER BY

SQL IN

SQL EXISTS

SQL BETWEEN

SQL LIKE

SQL ALIAS

SQL AGGREGATE

>SQL COUNT

>SQL SUM

>SQL MAX

>SQL MIN

>SQL AVG

SQL GROUP BY

SQL HAVING

SQL INSERT

SQL UPDATE

SQL DELETE

SQL SELECT INTO

SQL CREATE DATABASE

SQL CREATE TABLE

SQL DROP TABLE

SQL DROP DATABASE

SQL CREATE INDEX

SQL PRIMARY KEY

SQL FOREIGN KEY

SQL ALTER TABLE

SQL TRUNCATE TABLE

SQL JOIN

SQL INNER JOIN

SQL OUTER JOIN

SQL CROSS JOIN

SQL UNION

SQL UNION ALL

SQL INTERSECT



SQL INNER JOIN

A INNER JOIN command is queries that combine data from more than 1 table.
For two tables that want to join together need to have some data in common, like unique id that link this 2 tables together.

INNER JOIN will need a joining condition or connecting column to display out the joined data. 1 joining condition needs when we want to join 2 tables. If more than 2 tables want to join together, more joining condition or connecting column needed.

A connecting column should have values that match easily for both tables. Connecting columns almost always have the same datatype. The value in the connecting columns are join compatible or can say that the value are come from the same general class of data.

SQL INNER JOIN syntax:

SELECT *FROM [TABLE 1] INNER JOIN [TABLE 2]
ON [TABLE 1].[COLUMN NAME 1] = [TABLE 2].[COLUMN NAME 2]


EXAMPLE :

Letís say, we only want to join 2 tables below and display only PlayerName and DepartmentName

Table 1: GameScores

PlayerNameDepartmentIdScores
Jason13000
Irene11500
Jane21000
David22500
Paul32000
James32000

Table 2: Departments

DepartmentIdDepartmentName
1IT
2Marketing
3HR

The joining Condition will be DepartmentId of both tables.
SQL statement :

SELECT PlayerName, DepartmentName
FROM GameScores2 INNER JOIN Departments
ON GameScores2.DepartmentId = Departments.DepartmentId

Result:

PlayerNameDepartmentName
JasonIT
IreneIT
JaneMarketing
DavidMarketing
PaulHR
JamesHR