SQL INNER JOIN
SQL INNER JOIN clause is used to combine and extract rows from two or more tables by joining common field. This common field column is compared by comparison operators like =, <, >, <=, >= or <>. INNER JOIN is also called as equi-join and returns those rows with equal value in join column. INNER JOIN and JOIN both are same and provides similar output.
FROM Table1 INNER JOIN Table2
ON Table1.columnName = Table2.columnName
Here we will consider one example for INNER JOIN condition where we will use two tables named as SalesDetails and ClientDetails.
Table Name: SalesDetails
Table Name: ClientDetails
From above two tables, we need columns OrderID and OrderDate from SalesDetails table and one column ClientName from ClientDetails table and sorted in ascending order by OrderDate column. So to get the output from two tables we will use INNER JOIN query as given below.
SELECT OrderID, ClientName, OrderDate FROM SalesDetails INNER JOIN ClientDetails ON SalesDetails.ClientID = ClientDetails.ClientID ORDER BY OrderDate
You can see the output by joining two tables in result pane where required data is sorted by OrderDate column.
Let’s consider one more example with greater than operator (>) where OrderDate column is greater than 13-Aug-2015.
SELECT OrderID, ClientName, OrderDate FROM SalesDetails JOIN ClientDetails ON SalesDetails.ClientID = ClientDetails.ClientID AND OrderDate > '2015-08-13'
So, we have four such records as shown above.
Reference: Manzoor Siddiqui [www.SQLServerLog.com]