0% found this document useful (0 votes)
8 views

SQL - Join Query - 1keydata

Uploaded by

vickroid007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL - Join Query - 1keydata

Uploaded by

vickroid007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3/2/2016 SQL ­ Join Query | 1Keydata

SQL Join

SQL Data Warehousing CSS PHP HTML Database Normalization

SQL Tutorial
Basic SQL Commands
SQL SELECT
SQL DISTINCT
SQL WHERE SQL > SQL JOIN
SQL AND OR
Now we want to look at joins. To do joins correctly in SQL requires many of the elements we have introduced so far. Let's
SQL IN
have the following two tables,
SQL BETWEEN
SQL Wildcard Table Store_Information
SQL LIKE
SQL ORDER BY Store_Name Sales Txn_Date
SQL GROUP BY Los Angeles 1500 Jan-05-1999
SQL HAVING San Diego 250 Jan-07-1999
SQL ALIAS Los Angeles 300 Jan-08-1999
SQL AS Boston 700 Jan-08-1999
SQL SELECT UNIQUE
SQL JOIN Table Geography
SQL INNER JOIN
SQL OUTER JOIN Region_Name Store_Name
SQL LEFT OUTER JOIN East Boston
SQL CROSS JOIN East New York
SQL INSERT INTO West Los Angeles
SQL INSERT INTO SELECT West San Diego
SQL UPDATE
SQL DELETE FROM and we want to find out sales by region. We see that table Geography includes information on regions and stores, and tabl
Advanced SQL
Store_Information contains sales information for each store. To get the sales information by region, we have to combine th
from the two tables. Examining the two tables, we find that they are linked via the common field, "Store_Name". We will fi
SQL UNION
SQL statement and explain the use of each segment later:
SQL UNION ALL
SQL Inline View
SELECT A1.Region_Name REGION, SUM(A2.Sales) SALES
SQL INTERSECT FROM Geography A1, Store_Information A2
SQL MINUS WHERE A1.Store_Name = A2.Store_Name
SQL LIMIT GROUP BY A1.Region_Name;
SQL TOP
SQL Subquery Result:
SQL EXISTS
SQL CASE REGION SALES
SQL DECODE East 700
SQL AUTO INCREMENT West 2050
SQL IDENTITY
SEQUENCE & NEXTVAL The first two lines tell SQL to select two fields, the first one is the field "Region_Name" from table Geography (aliased as R
SQL Functions second one is the sum of the field "Sales" from table Store_Information (aliased as SALES). Notice how the table aliases ar
SQL Average Geography is aliased as A1, and Store_Information is aliased as A2. Without the aliasing, the first line would become
SQL COUNT
SELECT Geography.Region_Name REGION, SUM(Store_Information.Sales) SALES
SQL MAX
SQL MIN
SQL SUM
which is much more cumbersome. In essence, table aliases make the entire SQL statement easier to understand, especially
tables are included.
SQL ROUND

String Functions An alternative way to specify a join between tables is to use the JOIN and ON keywords. In the current example, the SQL q
SQL CAST
SQL CONVERT SELECT A1.Region_Name REGION, SUM(A2.Sales) SALES
SQL CONCATENATE FROM Geography A1
JOIN Store_Information A2
SQL SUBSTRING
ON A1.Store_Name = A2.Store_Name
SQL INSTR GROUP BY A1.Region_Name;
SQL TRIM

http://www.1keydata.com/sql/sqljoins.html 1/2
3/2/2016 SQL ­ Join Query | 1Keydata
SQL LENGTH Several different types of joins can be performed in SQL. The key ones are as follows:
SQL REPLACE
SQL TO_DATE Inner Join
Outer Join
Date Functions
Left Outer Join
Cross Join

The following sections explain each JOIN type in detail.

Next: SQL Inner Join

Google Web Hosting


Build Your Online Presence With Google Sites. Free 30­Day Trial!

Copyright © 2016 1keydata.com All Rights Reserved Privacy Policy About Contact

http://www.1keydata.com/sql/sqljoins.html 2/2

You might also like