SlideShare a Scribd company logo
SQL Basics
Introduction to
Standard Query Language
SQL โ€“ What Is It?
Structured Query Language
Common Language For Variety of
Databases
ANSI Standard BUTโ€ฆ.
Two Types of SQL
DML โ€“ Data Manipulation Language (SELECT)
DDL โ€“ Data Definition Language (CREATE
TABLE)
Where To Use
SQL*Plus
TOAD
SQL Navigator
ODBC Supported Connections
Excel
Access
Lotus 1-2-3

Heart of PL/SQL
Pros & Cons of SQL
Pros:
Very flexible
Universal (Oracle, Access, Paradox, etc)
Relatively Few Commands to Learn

Cons:
Requires Detailed Knowledge of the Structure
of the Database
Can Provide Misleading Results
Basic SQL Components
SELECT schema.table.column
FROM table alias

WHERE [conditions]
ORDER BY [columns]
;
Defines the end of an SQL statement
Some programs require it, some do not (TOAD Does
Not)
Needed only if multiple SQL statements run in a script

Optional Elements
SELECT Statement
SELECT Statement Defines WHAT is to be
returned (separated by commas)

Database Columns (From Tables or Views)
Constant Text Values
Formulas
Pre-defined Functions
Group Functions (COUNT, SUM, MAX, MIN, AVG)

โ€œ*โ€ Mean All Columns From All Tables In the
FROM Statement
Example: SELECT state_code, state_name
FROM Statement
Defines the Table(s) or View(s) Used by
the SELECT or WHERE Statements
You MUST Have a FROM statement
Multiple Tables/Views are separated by
Commas
Examples
SELECT state_name, state_abbr
FROM states
SELECT *
FROM agencies
SELECT arithmetic_mean โ€“ minimum_value
FROM annual_summaries
WHERE Clause
Optional
Defines what records are to be included in the query
Uses Conditional Operators
=, >, >=, <, <=, != (<>)
BETWEEN x AND y
IN (list)
LIKE โ€˜%stringโ€™ (โ€œ%โ€ is a wild-card)
IS NULL
NOT {BETWEEN / IN / LIKE / NULL}

Multiple Conditions Linked with AND & OR Statements
Strings Contained Within SINGLE QUOTES!!
AND & OR
Multiple WHERE conditions are Linked by AND /
OR Statements
โ€œANDโ€ Means All Conditions are TRUE for the
Record
โ€œORโ€ Means at least 1 of the Conditions is TRUE
You May Group Statements with ( )
BE CAREFUL MIXING โ€œANDโ€ & โ€œORโ€ Conditions
Examples with WHERE
SELECT *
FROM annual_summaries
WHERE sd_duration_code = โ€˜1โ€™
SELECT state_name
FROM states
WHERE state_population > 15000000
More Examples
SELECT state_name, state_population
FROM states
WHERE state_name LIKE โ€˜%NORTH%โ€™
SELECT *
FROM annual_summaries
WHERE sd_duration_code IN (โ€˜1โ€™, โ€˜Wโ€™, โ€˜Xโ€™)
AND annual_summary_year = 2000
Be Careful!
SELECT mo_mo_id, sd_duration_code
FROM annual_summaries
WHERE annual_summary_year = 2003
AND values_gt_pri_std > 0
OR values_gt_sec_std > 0
SELECT mo_mo_id, sd_duration_code
FROM annual_summaries
WHERE annual_summary_year = 2003
AND (values_gt_pri_std > 0
OR values_gt_sec_std > 0)
ORDER BY Statement
Defines How the Records are to be Sorted
Must be in the SELECT statement to be
ORDER BY
Default is to order in ASC (Ascending)
order
Can Sort in Reverse (Descending) Order
with โ€œDESCโ€ After the Column Name
ORDER BY Example
SELECT *
FROM agencies
ORDER BY agency_desc
SELECT cc_cn_stt_state_code, site_id
FROM sites
WHERE lut_land_use_type = โ€˜MOBILEโ€™
ORDER BY cc_cn_stt_state_code DESC
Group Functions
Performs Common Mathematical
Operations on a Group of Records
Must define what Constitutes a Group by
Using the GROUP BY Clause
All non-Group elements in the SELECT
Statement Must be in the GROUP BY
Clause (Additional Columns are Optional)
Group By Example
SELECT si_si_id, COUNT(mo_id)
FROM monitors
GROUP BY si_si_id
SELECT AVG(max_sample_value)
FROM summary_maximums
WHERE max_level <= 3
AND max_ind = โ€˜REGโ€™
GROUP BY ans_ans_id
OK, I understand How to Get Data
From 1 Tableโ€ฆ What about
Multiple Tables?
V_MONITOR_ID

MONITORS

PARAMETERS

PARAMETER_CODE
PARAMETER_DESC

MO_ID
SI_SI_ID
PA_PARAMETER_CODE
POC

MO_ID
AIRS_MONITOR_ID
STATE_CODE
COUNTY_CODE
SITE_ID
PARAMETER_CODE
POC
Primary & Foreign Keys
Primary Keys
1 or More Columns Used to Uniquely Identify
a record.
All Columns Defined as PKโ€™s MUST be
populated

Foreign Keys
Value on a table that references a Primary
Key from a different table
Primary & Foreign Keys
SITES

SI_ID%
SITE_LATITUDE
SITE_LONGITUDE
STREET_ADDRESS

PARAMETERS

PARAMETER_CODE%
PARAMETER_DESC

V_MONITOR_ID

MONITORS

MO_ID%
SI_SI_ID*
PA_PARAMETER_CODE*
POC

* = Foreign Key
% = Primary Key

MO_ID
STATE_CODE
COUNTY_CODE
SITE_ID
PARAMETER_CODE
POC
Joining Tables
MONITORS

PARAMETERS
MO_ID

SI_SI_ID

PA_PARAMETER_CODE

POC

Parameter_Code

Parameter_Desc

1

1

44201

1

44201

Ozone

2

1

42101

1

3

1

42101

2

4

2

81102

1

42101

CO

42401

SO2

5

2

44201

1

81102

PM10

6

3

42401

1

Default behavior is to show every possible combination between the two tables
Cartesian Join / Simple Join
SELECT mo_id, poc, parameter_desc
FROM monitors, parameters
MONITORS

PARAMETERS
MO_ID

SI_SI_ID

PA_PARAMETER_CODE

POC

Parameter_Code

Parameter_Desc

1

1

44201

1

44201

Ozone

2

1

42101

1

3

1

42101

2

4

2

81102

1

42101

CO

42401

SO2

5

2

44201

1

81102

PM10

6

3

42401

1
Joining Tables
SELECT mo_id, poc, parameter_desc
FROM monitors, parameters
WHERE pa_parameter_code = parameter_code
MONITORS

PARAMETERS
MO_ID

SI_SI_ID

PA_PARAMETER_CODE

POC

Parameter_Code

Parameter_Desc

1

1

44201

1

44201

Ozone

2

1

42101

1

3

1

42101

2

4

2

81102

1

42101

CO

42401

SO2

5

2

44201

1

81102

PM10

6

3

42401

1
Joining Tables
Joins Between Tables are Usually Based
on Primary / Foreign Keys
Make Sure Joins Between All Tables in the
FROM Clause Exist
List Joins Between Tables Before Other
Selection Elements
Aliases
โ€œShorthandโ€ for Table or Column
References
SELECT Aliases Appear as Column
Headers in the Output
Aliases Cannot be Keywords
Previous SQL With Aliases
SELECT mo.mo_id, mo.poc, pa.parameter_desc parameter
FROM monitors mo, parameters pa
WHERE mo.pa_parameter_code = pa.parameter_code
Why Use an Alias?
Saves Typing
Good Internal Documentation
Better Headers
If the same column name exists on
multiple tables, SQL needs a way to know
which element you are referencing
(MO_MO_ID for example)
Recap
Basic Structural Elements
SELECT
FROM
WHERE
ORDER BY
GROUP BY

Selecting From Multiple Tables
Join Multiple Tables via Primary & Foreign Keys
Aliases

More Related Content

What's hot

06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinct
Bishal Ghimire
ย 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
Nalina Kumari
ย 
Complete Sql Server querries
Complete Sql Server querriesComplete Sql Server querries
Complete Sql Server querries
Ibrahim Jutt
ย 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
ย 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
Mahir Haque
ย 
Sql
SqlSql
Sql
Diana Diana
ย 
Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
Ram Kedem
ย 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
bixxman
ย 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
gaurav koriya
ย 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
Achmad Solichin
ย 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
Prithwis Mukerjee
ย 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
ย 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
Edureka!
ย 
Excel tutorial
Excel tutorialExcel tutorial
Excel tutorial
beethoven jon ocubillo
ย 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
Achmad Solichin
ย 
Sql basics v2
Sql basics v2Sql basics v2
Sql basics v2
Yousuf Akhtar Sultan
ย 

What's hot (16)

06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinct
ย 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
ย 
Complete Sql Server querries
Complete Sql Server querriesComplete Sql Server querries
Complete Sql Server querries
ย 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
ย 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
ย 
Sql
SqlSql
Sql
ย 
Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
ย 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
ย 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
ย 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
ย 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
ย 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
ย 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
ย 
Excel tutorial
Excel tutorialExcel tutorial
Excel tutorial
ย 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
ย 
Sql basics v2
Sql basics v2Sql basics v2
Sql basics v2
ย 

Viewers also liked

Sql basics
Sql  basicsSql  basics
Sql basics
Genesis Omo
ย 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
jhe04
ย 
Sql Basic Selects
Sql Basic SelectsSql Basic Selects
Sql Basic Selects
Bob Litsinger
ย 
Sql basics joi ns and common commands (1)
Sql basics  joi ns and common commands (1)Sql basics  joi ns and common commands (1)
Sql basics joi ns and common commands (1)
johnnygoodman
ย 
Lecture 07 - Basic SQL
Lecture 07 - Basic SQLLecture 07 - Basic SQL
Lecture 07 - Basic SQL
University of Massachusetts Amherst
ย 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
Varun A M
ย 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
Salman Memon
ย 
Introduction to MySQL and phpMyAdmin
Introduction to MySQL and phpMyAdminIntroduction to MySQL and phpMyAdmin
Introduction to MySQL and phpMyAdmin
Drake Huang
ย 
Tables And SQL basics
Tables And SQL basicsTables And SQL basics
Tables And SQL basics
Amit Kumar Singh
ย 
Pl sql guide
Pl sql guidePl sql guide
Pl sql guide
Vinay Kumar
ย 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
koolkampus
ย 
SQL212.2 Introduction to SQL using Oracle Module 2
SQL212.2 Introduction to SQL using Oracle Module 2SQL212.2 Introduction to SQL using Oracle Module 2
SQL212.2 Introduction to SQL using Oracle Module 2
Dan D'Urso
ย 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
Hammad Rasheed
ย 
MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining Databases
DataminingTools Inc
ย 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
Pongsakorn U-chupala
ย 
College management system ppt
College management system pptCollege management system ppt
College management system ppt
Shanthan Reddy
ย 
Database management system presentation
Database management system presentationDatabase management system presentation
Database management system presentation
sameerraaj
ย 
Ms excel 2007
Ms excel 2007Ms excel 2007
Ms excel 2007
rgaotbgal261415
ย 

Viewers also liked (19)

Sql basics
Sql  basicsSql  basics
Sql basics
ย 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
ย 
Sql Basic Selects
Sql Basic SelectsSql Basic Selects
Sql Basic Selects
ย 
Sql basics joi ns and common commands (1)
Sql basics  joi ns and common commands (1)Sql basics  joi ns and common commands (1)
Sql basics joi ns and common commands (1)
ย 
Lecture 07 - Basic SQL
Lecture 07 - Basic SQLLecture 07 - Basic SQL
Lecture 07 - Basic SQL
ย 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
ย 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
ย 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
ย 
Introduction to MySQL and phpMyAdmin
Introduction to MySQL and phpMyAdminIntroduction to MySQL and phpMyAdmin
Introduction to MySQL and phpMyAdmin
ย 
Tables And SQL basics
Tables And SQL basicsTables And SQL basics
Tables And SQL basics
ย 
Pl sql guide
Pl sql guidePl sql guide
Pl sql guide
ย 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
ย 
SQL212.2 Introduction to SQL using Oracle Module 2
SQL212.2 Introduction to SQL using Oracle Module 2SQL212.2 Introduction to SQL using Oracle Module 2
SQL212.2 Introduction to SQL using Oracle Module 2
ย 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
ย 
MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining Databases
ย 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
ย 
College management system ppt
College management system pptCollege management system ppt
College management system ppt
ย 
Database management system presentation
Database management system presentationDatabase management system presentation
Database management system presentation
ย 
Ms excel 2007
Ms excel 2007Ms excel 2007
Ms excel 2007
ย 

Similar to Sql basics

Sql General
Sql General Sql General
Sql General
Praveen Tiwari
ย 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
osama majid
ย 
Sql 2006
Sql 2006Sql 2006
Sql 2006
Cathie101
ย 
Sql
SqlSql
Query
QueryQuery
Query
Raj Devaraj
ย 
Sql
SqlSql
Sql
navsissuk
ย 
Hira
HiraHira
Hira
hira elahi
ย 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
Balqees Al.Mubarak
ย 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SabrinaShanta2
ย 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SaiMiryala1
ย 
SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
AnishurRehman1
ย 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
SARVESH KUMAR
ย 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
BhupendraShahi6
ย 
Sql functions
Sql functionsSql functions
Sql functions
G C Reddy Technologies
ย 
Dbms
DbmsDbms
Dbms
Sachin Yadav
ย 
SQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxSQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptx
ssuser6bf2d1
ย 
SQL Query
SQL QuerySQL Query
SQL Query
Imam340267
ย 
Lecture5-SQL.docx
Lecture5-SQL.docxLecture5-SQL.docx
Lecture5-SQL.docx
ismailaboshatra
ย 
Stored procedures
Stored proceduresStored procedures
SQL
SQLSQL
SQL
Jerin John
ย 

Similar to Sql basics (20)

Sql General
Sql General Sql General
Sql General
ย 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
ย 
Sql 2006
Sql 2006Sql 2006
Sql 2006
ย 
Sql
SqlSql
Sql
ย 
Query
QueryQuery
Query
ย 
Sql
SqlSql
Sql
ย 
Hira
HiraHira
Hira
ย 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
ย 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
ย 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
ย 
SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
ย 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
ย 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
ย 
Sql functions
Sql functionsSql functions
Sql functions
ย 
Dbms
DbmsDbms
Dbms
ย 
SQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxSQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptx
ย 
SQL Query
SQL QuerySQL Query
SQL Query
ย 
Lecture5-SQL.docx
Lecture5-SQL.docxLecture5-SQL.docx
Lecture5-SQL.docx
ย 
Stored procedures
Stored proceduresStored procedures
Stored procedures
ย 
SQL
SQLSQL
SQL
ย 

Recently uploaded

Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
ย 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
ย 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
ย 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
ย 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
Celine George
ย 
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Nguyen Thanh Tu Collection
ย 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
ย 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
ย 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
ย 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
ย 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
ย 
Juneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School DistrictJuneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School District
David Douglas School District
ย 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
ย 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
ย 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
ย 
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ   ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdfู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ   ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ
ย 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
ย 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
ย 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
ย 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
ย 

Recently uploaded (20)

Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
ย 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
ย 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
ย 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
ย 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
ย 
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
Bร€I TแบฌP Bแป” TRแปข TIแบพNG ANH LแปšP 9 Cแบข Nฤ‚M - GLOBAL SUCCESS - Nฤ‚M HแปŒC 2024-2025 - ...
ย 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
ย 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
ย 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
ย 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
ย 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
ย 
Juneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School DistrictJuneteenth Freedom Day 2024 David Douglas School District
Juneteenth Freedom Day 2024 David Douglas School District
ย 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
ย 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
ย 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
ย 
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ   ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdfู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ   ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ย 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
ย 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
ย 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
ย 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
ย 

Sql basics

  • 2. SQL โ€“ What Is It? Structured Query Language Common Language For Variety of Databases ANSI Standard BUTโ€ฆ. Two Types of SQL DML โ€“ Data Manipulation Language (SELECT) DDL โ€“ Data Definition Language (CREATE TABLE)
  • 3. Where To Use SQL*Plus TOAD SQL Navigator ODBC Supported Connections Excel Access Lotus 1-2-3 Heart of PL/SQL
  • 4. Pros & Cons of SQL Pros: Very flexible Universal (Oracle, Access, Paradox, etc) Relatively Few Commands to Learn Cons: Requires Detailed Knowledge of the Structure of the Database Can Provide Misleading Results
  • 5. Basic SQL Components SELECT schema.table.column FROM table alias WHERE [conditions] ORDER BY [columns] ; Defines the end of an SQL statement Some programs require it, some do not (TOAD Does Not) Needed only if multiple SQL statements run in a script Optional Elements
  • 6. SELECT Statement SELECT Statement Defines WHAT is to be returned (separated by commas) Database Columns (From Tables or Views) Constant Text Values Formulas Pre-defined Functions Group Functions (COUNT, SUM, MAX, MIN, AVG) โ€œ*โ€ Mean All Columns From All Tables In the FROM Statement Example: SELECT state_code, state_name
  • 7. FROM Statement Defines the Table(s) or View(s) Used by the SELECT or WHERE Statements You MUST Have a FROM statement Multiple Tables/Views are separated by Commas
  • 8. Examples SELECT state_name, state_abbr FROM states SELECT * FROM agencies SELECT arithmetic_mean โ€“ minimum_value FROM annual_summaries
  • 9. WHERE Clause Optional Defines what records are to be included in the query Uses Conditional Operators =, >, >=, <, <=, != (<>) BETWEEN x AND y IN (list) LIKE โ€˜%stringโ€™ (โ€œ%โ€ is a wild-card) IS NULL NOT {BETWEEN / IN / LIKE / NULL} Multiple Conditions Linked with AND & OR Statements Strings Contained Within SINGLE QUOTES!!
  • 10. AND & OR Multiple WHERE conditions are Linked by AND / OR Statements โ€œANDโ€ Means All Conditions are TRUE for the Record โ€œORโ€ Means at least 1 of the Conditions is TRUE You May Group Statements with ( ) BE CAREFUL MIXING โ€œANDโ€ & โ€œORโ€ Conditions
  • 11. Examples with WHERE SELECT * FROM annual_summaries WHERE sd_duration_code = โ€˜1โ€™ SELECT state_name FROM states WHERE state_population > 15000000
  • 12. More Examples SELECT state_name, state_population FROM states WHERE state_name LIKE โ€˜%NORTH%โ€™ SELECT * FROM annual_summaries WHERE sd_duration_code IN (โ€˜1โ€™, โ€˜Wโ€™, โ€˜Xโ€™) AND annual_summary_year = 2000
  • 13. Be Careful! SELECT mo_mo_id, sd_duration_code FROM annual_summaries WHERE annual_summary_year = 2003 AND values_gt_pri_std > 0 OR values_gt_sec_std > 0 SELECT mo_mo_id, sd_duration_code FROM annual_summaries WHERE annual_summary_year = 2003 AND (values_gt_pri_std > 0 OR values_gt_sec_std > 0)
  • 14. ORDER BY Statement Defines How the Records are to be Sorted Must be in the SELECT statement to be ORDER BY Default is to order in ASC (Ascending) order Can Sort in Reverse (Descending) Order with โ€œDESCโ€ After the Column Name
  • 15. ORDER BY Example SELECT * FROM agencies ORDER BY agency_desc SELECT cc_cn_stt_state_code, site_id FROM sites WHERE lut_land_use_type = โ€˜MOBILEโ€™ ORDER BY cc_cn_stt_state_code DESC
  • 16. Group Functions Performs Common Mathematical Operations on a Group of Records Must define what Constitutes a Group by Using the GROUP BY Clause All non-Group elements in the SELECT Statement Must be in the GROUP BY Clause (Additional Columns are Optional)
  • 17. Group By Example SELECT si_si_id, COUNT(mo_id) FROM monitors GROUP BY si_si_id SELECT AVG(max_sample_value) FROM summary_maximums WHERE max_level <= 3 AND max_ind = โ€˜REGโ€™ GROUP BY ans_ans_id
  • 18. OK, I understand How to Get Data From 1 Tableโ€ฆ What about Multiple Tables? V_MONITOR_ID MONITORS PARAMETERS PARAMETER_CODE PARAMETER_DESC MO_ID SI_SI_ID PA_PARAMETER_CODE POC MO_ID AIRS_MONITOR_ID STATE_CODE COUNTY_CODE SITE_ID PARAMETER_CODE POC
  • 19. Primary & Foreign Keys Primary Keys 1 or More Columns Used to Uniquely Identify a record. All Columns Defined as PKโ€™s MUST be populated Foreign Keys Value on a table that references a Primary Key from a different table
  • 20. Primary & Foreign Keys SITES SI_ID% SITE_LATITUDE SITE_LONGITUDE STREET_ADDRESS PARAMETERS PARAMETER_CODE% PARAMETER_DESC V_MONITOR_ID MONITORS MO_ID% SI_SI_ID* PA_PARAMETER_CODE* POC * = Foreign Key % = Primary Key MO_ID STATE_CODE COUNTY_CODE SITE_ID PARAMETER_CODE POC
  • 22. Cartesian Join / Simple Join SELECT mo_id, poc, parameter_desc FROM monitors, parameters MONITORS PARAMETERS MO_ID SI_SI_ID PA_PARAMETER_CODE POC Parameter_Code Parameter_Desc 1 1 44201 1 44201 Ozone 2 1 42101 1 3 1 42101 2 4 2 81102 1 42101 CO 42401 SO2 5 2 44201 1 81102 PM10 6 3 42401 1
  • 23. Joining Tables SELECT mo_id, poc, parameter_desc FROM monitors, parameters WHERE pa_parameter_code = parameter_code MONITORS PARAMETERS MO_ID SI_SI_ID PA_PARAMETER_CODE POC Parameter_Code Parameter_Desc 1 1 44201 1 44201 Ozone 2 1 42101 1 3 1 42101 2 4 2 81102 1 42101 CO 42401 SO2 5 2 44201 1 81102 PM10 6 3 42401 1
  • 24. Joining Tables Joins Between Tables are Usually Based on Primary / Foreign Keys Make Sure Joins Between All Tables in the FROM Clause Exist List Joins Between Tables Before Other Selection Elements
  • 25. Aliases โ€œShorthandโ€ for Table or Column References SELECT Aliases Appear as Column Headers in the Output Aliases Cannot be Keywords
  • 26. Previous SQL With Aliases SELECT mo.mo_id, mo.poc, pa.parameter_desc parameter FROM monitors mo, parameters pa WHERE mo.pa_parameter_code = pa.parameter_code
  • 27. Why Use an Alias? Saves Typing Good Internal Documentation Better Headers If the same column name exists on multiple tables, SQL needs a way to know which element you are referencing (MO_MO_ID for example)
  • 28. Recap Basic Structural Elements SELECT FROM WHERE ORDER BY GROUP BY Selecting From Multiple Tables Join Multiple Tables via Primary & Foreign Keys Aliases