Introduction

This article starts with the basics of the SQL keyword. These keywords are for data filtration in a SQL database table.

From Command

SQL
Select * From TableName  
Select Column From TableName

Example

SQL
select * from Info   
select Name from Info

Getting Started With Basic SQL Keywords And SQL Join

Where Command

SQL
Select * from TableName where Condition  
Select column1, column2 from TableName where Condition

Example

SQL
select * from Info where City = 'Ahmedabad'  
select Name from Info where city = 'Surat'

Getting Started With Basic SQL Keywords And SQL Join

Top Command

This command selects the top rows in a database table.

SQL
Select Top value from TableName

Example

SQL
select Top 3 * from Info   
select Top (25) percent * from Info

Getting Started With Basic SQL Keywords And SQL Join

As Command

Use for Alias Keyword.

SQL
Select ExitingColumnName AS NewAliasColumnName from TableName

Example

SQL
Select Name From Info  
select Name AS [Person Name] from Info

Getting Started With Basic SQL Keywords And SQL Join

AND Command

SQL
select * from TableName where condition1 AND Condition2  
select ColumnName from TableName where condition1 AND Condition2

Example

SQL
select * from Info where Name='Rakesh' And City= 'Ahmedabad'  
Select * From info where Name='Rakesh' And City = 'Surat'

Getting Started With Basic SQL Keywords And SQL Join

OR Command

SQL
select * from TableName where condition1 OR Condition2  
select ColumnName from TableName where condition1 OR Condition2

Example

SQL
select * from Info where Name='Rakesh' OR City= 'Ahmedabad'  
Select * From info where Name='Rakesh' OR City = 'Surat'

Getting Started With Basic SQL Keywords And SQL Join

Between Command

SQL
Select * from TableName where columnCondition Between StartValue AND EndValue

Example

SQL
select * from Info  
select * from info where id Between 3 AND 5

Getting Started With Basic SQL Keywords And SQL Join

IN Command

SQL
select * from TableName where condition IN (‘DATAValue’)

Example

SQL
select * from Info where city in ('Ahmedabad')  
select * from Info where city in ('Goa','Surat')

Getting Started With Basic SQL Keywords And SQL Join

LIKE Command

SQL
select * from TableName From ColumnName LIKE ‘%VALUE%’

Example

SQL
select * from Info where city like '%Goa%'  
Select * from Info Where City like '%Ahm%'  
Select * from Info where Name like '%esh%'  
Select * from Info where id like '%3%'

Getting Started With Basic SQL Keywords And SQL Join

Distinct Command

Don't display the same multiple records.

SQL
Select DISTINCT ColumnName From TableName

Example

SQL
select City from Info  
Select DISTINCT City from Info

Getting Started With Basic SQL Keywords And SQL Join

Order By Command

Sorts data in ascending or descending order.

SQL
Select * from TableName Order By ColumnName ASC | DESC  
Select columnName from TableName Order By ColumnName ASC | DESC

Example

SQL
Select * from Info order by Name ASC --ascending order by Name Column  
Select Name from Info order by Name DESC --descending order by Name Column

Getting Started With Basic SQL Keywords And SQL Join

Group By Command

Selects data in a group.

SQL
Select conditionwithcolumn from TableName Group by ColumnName

Example

SQL
select city, count(Name) As Number_of_Person from Info Group by City

Getting Started With Basic SQL Keywords And SQL Join

Counts the total number of people in each city.

SQL Join

A join is the most important concept of SQL databases. In this, any two or more tables are joined with the same data column field. Many types of joins are available in SQL Server.

Find a detailed article about joins in SQL Server here: Joins in SQL Server.

Basic Command

SQL
Select column1, column2   
From Table1  
[Type of Join] Table2   
ON condition

Cross Join

All data records are selected from the selected database table.

Command

SQL
Select column from Table1 CROSS JOIN Table2

Example

SQL
select EmployeeData.EmployeeID,EmployeeData.EmployeeName,Department.Department  
from EmployeeData  
Cross Join Department

Getting Started With Basic SQL Keywords And SQL Join

If 5 data records are in Table1 and 2 in Table2, then in a cross join, the output is from both tables and is multiple records.

Example

SQL
[5 record * 2 record = Total 10 records display]

Inner Join

Command

SQL
Select Table1.column,  
Table2.column,  
From Table1   
Inner join Table2 ON Table1.ColumnID = Table2.ColumnID

Example

SQL
select EmployeeData.EmployeeID,  
EmployeeData.EmployeeName,  
Department.Department  
From EmployeeData  
Inner Join Department  
ON EmployeeData.DepartmentID=Department.DepartmentID

Getting Started With Basic SQL Keywords And SQL Join

Outer Join

Two types of outer joins in SQL database.

Left Outer Join

Command

SQL
Select Table1.column,  
Table2.column,  
From Table1   
Left outer join Table2 ON Table1.ColumnID = Table2.ColumnID

Example

SQL
select EmployeeData.EmployeeID,EmployeeData.EmployeeName,  
Department.DepartmentID,Department.Department  
From EmployeeData  
LEFT Outer Join Department  
ON EmployeeData.DepartmentID=Department.DepartmentID

Getting Started With Basic SQL Keywords And SQL Join

Right Outer Join

Command Example

Getting Started With Basic SQL Keywords And SQL Join

SQL
Select Table1.column,  
Table2.column,  
From Table1   
Right outer join Table2 ON Table1.ColumnID = Table2.ColumnID  
select EmployeeData.EmployeeID,EmployeeData.EmployeeName,  
Department.DepartmentID,Department.Department  
From EmployeeData  
Right Outer Join Department  
ON EmployeeData.DepartmentID=Department.DepartmentID

Union Command

SQL
Select column1, column2   
from Table1  
TypeofJoin Teble2  
ON Table1.ColumnID = Table2.ColumnID  
UNION   
Select column1, column2   
from Table1  
TypeofJoin Teble2  
ON Table1.ColumnID = Table2.ColumnID

Example

SQL
Select EmployeeID,EmployeeName,Department  
From EmployeeData  
Left outer Join Department   
On EmployeeData.EmployeeID = Department.DepartmentID  
Union  
Select EmployeeID,EmployeeName,Department  
From EmployeeData  
Right outer Join Department   
On EmployeeData.EmployeeID = Department.DepartmentID

Getting Started With Basic SQL Keywords And SQL Join

Union ALL Command

SQL
Select column1, column2   
from Table1  
TypeofJoin Teble2  
ON Table1.ColumnID = Table2.ColumnID  
UNION ALL  
Select column1, column2   
from Table1  
TypeofJoin Teble2  
ON Table1.ColumnID = Table2.ColumnID

Example

SQL
Select EmployeeID,EmployeeName,Department  
From EmployeeData  
Left outer Join Department   
On EmployeeData.EmployeeID = Department.DepartmentID  
Union ALL  
Select EmployeeID,EmployeeName,Department  
From EmployeeData  
Right outer Join Department   
On EmployeeData.EmployeeID = Department.DepartmentID

Getting Started With Basic SQL Keywords And SQL Join

Summary

I hope you understand SQL database condition keywords and joins.

Reference