0% found this document useful (0 votes)
309 views2 pages

Understanding SQL Inner Join Basics

SQL INNER JOIN clause is used to select data from 2 (or more) tables, at least one match in both tables.

Uploaded by

sqls666
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
309 views2 pages

Understanding SQL Inner Join Basics

SQL INNER JOIN clause is used to select data from 2 (or more) tables, at least one match in both tables.

Uploaded by

sqls666
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

SQL INNER JOIN

SQL INNER JOIN clause is used to select data from 2 (or more) tables, at least one
match in both tables.

SQL INNER JOIN Clause Syntax

SELECT Table1.Column1, Table1.Column2, ... , 
Table2.Column1, Table2.Column2, ...  

FROM Table1  

INNER JOIN Table2  

ON Table1.ColumnName = Table2.ColumnName  

Note: SQL INNER JOIN is the default type of SQL JOIN. “JOIN” = “INNER JOIN”

SQL INNER JOIN Clause Example

Table: Employees

EmployeeId FirstName LastName Department Salary


203 Mazojys Fxoj Finance 78000
204 Jozzh Lnanyo Finance 45800
205 Syllauu Dfaafk Finance 57000
206 Gecrrcc Srlkrt Finance 62000

Table: Tickets

TicketID TicketNo EmployeeId


1 2349 203
2 2400 204
3 2438 205

Select all the employees with any tickets:

SELECT Employees.EmployeeId  
           , Employees.FirstName  
           , Employees.LastName  
           , Tickets.TicketNo  

FROM Employees  
INNER JOIN Tickets  

ON Employees.EmployeeId = Tickets.EmployeeId  
The result will look like:

EmployeeId FirstName LastName TicketNo


203 Mazojys Fxoj 2349
204 Jozzh Lnanyo 2400
205 Syllauu Dfaafk 2438

Note: The employee whose EmployeeId is 206 doesn’t have any records matched in the
table Tickets, so this employee will not in the result.

As mentioned above, “JOIN” = “INNER JOIN”, so, the following statement has the same
result:

SELECT Employees.EmployeeId  
           , Employees.FirstName  
           , Employees.LastName  
           , Tickets.TicketNo  

FROM Employees  

JOIN Tickets  

ON Employees.EmployeeId = Tickets.EmployeeId  

In most database systems, we can even write it shorter:

SELECT Employees.EmployeeId  
           , Employees.FirstName  
           , Employees.LastName  
           , Tickets.TicketNo  

FROM Employees, Tickets  

WHERE Employees.EmployeeId = Tickets.EmployeeId  

Ref: http://www.sql-statements.com/sql-inner-join.html

SQL INNER JOIN

You might also like