An Introduction to SQL.

Slides:



Advertisements
Similar presentations
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Advertisements

SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
CIT 613: Relational Database Development using SQL Introduction to SQL.
Chapter 1: Getting Started
Introduction to SQL Session 1 Retrieving Data From a Single Table.
SQL/Server Stephen Cunningham Thema Davis. Problem Domain Designed for retrieval and management of data Defines the structures and operations of a data.
PROC SQL – Select Codes To Master For Power Programming Codes and Examples from SAS.com Nethra Sambamoorthi, PhD Northwestern University Master of Science.
Database Lecture # 1 By Ubaid Ullah.
Attribute Data in GIS Data in GIS are stored as features AND tabular info Tabular information can be associated with features OR Tabular data may NOT be.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
Chapter 9 Joining Data from Multiple Tables
PROC SQL Phil Vecchione. SQL Structured Query Language Developed by IBM in the early 1970’s From the 70’s to the late 80’s there were different types.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Using Special Operators (LIKE and IN)
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
SQL 101 – Class 1 Lee Turner. Agenda 1. This is your life – SQL A brief history of SQL What SQL is and what it is not Normalization 2. Some Super Simple.
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Database Concepts Track 3: Managing Information using Database.
SQL Overview Structured Query Language. Description  When Codd first described the theory of relational databases, he asserted that there should be a.
CIT 613: Relational Database Development using SQL Introduction to SQL DeSiaMorePowered by DeSiaMore 1.
(SQL - Structured Query Language)
WEEK# 12 Haifa Abulaiha November 02,
SQL. Originally developed by IBM Standardized in 80’s by ANSI and ISO Language to access relational database and English-like non-procedural Predominant.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
® Microsoft Access 2010 Tutorial 9 Using Action Queries and Advanced Table Relationships.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
IFS180 Intro. to Data Management Chapter 10 - Unions.
SQL - Training Rajesh Charles. Agenda (Complete Course) Introduction Testing Methodologies Manual Testing Practical Workshop Automation Testing Practical.
Understanding Core Database Concepts Lesson 1. Objectives.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
Session 1 Retrieving Data From a Single Table
INTRODUCTION TO DATABASES (MICROSOFT ACCESS)
DATA MANAGEMENT MODULE: USING SQL in R
Putting tables together
Database Systems: Design, Implementation, and Management Tenth Edition
Objectives Create an action query to create a table
Information Systems Database Management
Database Management  .
Basic Queries Specifying Columns
PROC SQL, Overview.
Databases and Information Management
DATA MANAGEMENT MODULE: USING SQL in R
Using SQL to Prepare Data for Analysis
Noncorrelated subquery
Database.
Displaying Queries 2 Display a query’s results in a specified order.
Outer Joins Inner joins returned only matching rows. When you join tables, you might want to include nonmatching rows as well as matching rows.
Structured Query Language
Introduction To Structured Query Language (SQL)
Inner Joins.
Databases and Information Management
Dictionary Tables and Views, obtain information about SAS files
Combining Data Sets in the DATA step.
Structured Query Language – The Fundamentals
Introduction To Structured Query Language (SQL)
Example, Create an analytic file for Nhanes 1999
Introduction to Subqueries, An Example
A new keyword -- calculated
Subqueries.
Database Systems: Design, Implementation, and Management Tenth Edition
UNION Operator keywords Displays all rows from both the tables
Remerging Summary Values
Understanding Core Database Concepts
Manipulating Data Lesson 3.
Hans Baumgartner Penn State University
Tutorial 9 Using Action Queries and Advanced Table Relationships
Presentation transcript:

An Introduction to SQL

Structured Query Language Structured Query Language (SQL) is a standardized language originally designed as a relational database query tool. SQL is currently used in software products to retrieve and update data.

Structured Query Language: Timeline 1970 1980 1990 2000 IBM develops SQL. 1970 – Dr. E. F. Codd of IBM proposes SQL. 1981 – First commercial SQL product is released. 1989 – More than 75 SQL-based systems exist. SAS 6.06 includes PROC SQL. 1999 – PROC SQL is enhanced for SAS 8. 2004 – PROC SQL is enhanced for SAS®9.

The SQL Procedure Enables the use of SQL in SAS Part of Base SAS Follows American National Standards Institute (ANSI) standards Includes enhancements for compatibility with SAS software

PROC SQL Features

Query SAS data sets proc sql ; select * from orion.employee_payroll having salary=max(salary) ; quit;

Generate reports from SAS data sets proc sql ; select mean(salary) "Average Salary" format=dollar12., employee_gender from orion.employee_payroll group by employee_gender ; quit;

Combine SAS data sets in many ways Inner Joins Full Right Left Outer Joins

Inner joins Return only matching rows Maximum of 256 tables can be joined at the same time.

Outer Joins Return all matching rows, plus nonmatching rows from one or both tables Can be performed on only two tables or views at a time. Left Full Right

Create and delete SAS data sets, views, and indexes proc sql ; create table newbp as select mean(BPXSY1,BPXSY2,BPXSY3,BPXSY4) as mnsbp, mean(BPXDI1,BPXDI2,BPXDI3,BPXDI4) as mndbp, seqn from nh9.bloodpressure ; select n(mnsbp) "mnsbp",n(mndbp) "mndbp" from newbp quit;

Update existing SAS data sets data tmp; input x b $ @@; datalines; 1 a1 1 a2 2 b1 2 b2 4 d ; proc print data=tmp; title "tmp"; run; title; proc sql; update tmp set x=x*2 where b contains "a"; select * from tmp; quit;

Access Meta Data proc sql ; select memname,name,label from dictionary.columns where libname="FRAM" and upcase(label) contains "CHOL"; quit;

Create Macro Variables proc sql ; select mean(age) into : mnage from fram.framexam5subset ; quit; %put Average age: &mnage;

(Sometimes) reproduce the results of multiple DATA and procedure steps with a single query proc sql; create table analysis as select a.seqn,mortstat=1 as dead,permth_exm, mean(BPXSY1,BPXSY2,BPXSY3,BPXSY4) as mnsbp, mean(BPXDI1,BPXDI2,BPXDI3,BPXDI4) as mndbp, riagendr=1 as male, ridageyr as age, ridreth2 as race_ethn, lbdhdl as hdl, lbxtc as chol, bmxbmi as bmi from nh9.mortality(keep=seqn eligstat mortstat permth_exm) a, nh9.bloodpressure(keep=seqn bpxsy1-bpxsy4 BPXDI1-BPXDI4) b, nh9.demographics (keep=seqn ridageyr riagendr RIDRETH2) c, nh9.bodymeasurements(keep=seqn bmxbmi) d, nh9.cholesterolhdl(keep= seqn LBDHDL LBXTC) e where eligstat eq 1 and a.seqn=b.seqn and b.seqn=c.seqn and c.seqn=d.seqn and d.seqn=e.seqn order by seqn ; quit; Example from Create Nhanes1999 Analytic File, 11 data/sort steps replaced by one sql

Structured Query Language Input Output SAS Data Set Report PROC SQL PROC SQL DBMS Table SAS Data Set SAS Data View SAS Data View DBMS Table

Terminology Data Processing SAS SQL File Data Set Table Record Observation Row Field Variable Column

The SQL Procedure Tool for querying data Tool for data manipulation and management An augmentation to the DATA step not A DATA step replacement