SlideShare a Scribd company logo
SQL200 SQL Programming Based on  SQL Clearly Explained  by Jan Harrington Module  1 – Relational Database Background, Basic Single Table Retrieval Operations Bookstore SQL200  Module 1
Note on SQL200 Slides These slides were originally designed to support the single SQL200 course which was used for any of MS Access, MySQL, Oracle and SQL Server. As such you may see here slides developed in any one of the above products. We are in the process of migrating the Oracle slides and the MS Access slides out into their own slide sets.  The SQL200 slides will cover MySQL and SQL Server which are virtually identical for purposes of this course. Bookstore2 SQL200  Module 2
Warning! Below are some table name changes to be aware of in doing queries. We have created synonyms so either name should work. Bookstore2 SQL200  Module 2 New Name Old Name Orders Order_filled Order_Lines Orderlines
SQL200 Contact Information Bookstore2 SQL200  Module 2 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address]   Copyright 2001-2011. All rights reserved.
SQL200 Resources Bookstore database scripts found on box.net at http://tinyurl.com/SQLScripts   Slides can be viewed on SlideShare… http://www.slideshare.net/OCDatabases   Follow up questions? [email_address]   Bookstore SQL212  Module 1
SQL Programming Course focus is SQL language Widely used for: Database administration Enterprise application development Data driven web sites A foundation skill for eBusiness and almost all major business applications that use relational databases Bookstore SQL200  Module 1
SQL Programming A basic knowledge of query systems, perhaps via MS Access,  or some programming knowledge, is desirable We will use GUI tools or SQL Plus almost exclusively Bookstore SQL200  Module 1
Relational Database Evolution Based on Codd’s paper Early commercial efforts focused on Unix First mainframe implementation by IBM  - precursor to today’s DB2 First PC implementation in early 80’s by Oracle Bookstore SQL200  Module 1
Relational Database Basics Storage Databases Tables Rows Columns Indexes Views Cursors Application interfaces Bookstore SQL200  Module 1
Bookstore SQL200  Module 1 Relational Database Table
Constraints Database Domain Uniqueness Relationship Cardinality 1 to 1 1 to N Other Business Rule Triggers Stored Procedures Bookstore SQL200  Module 1
Bookstore SQL200  Module 1 Relational Database with constraints
Database Management Systems Bookstore SQL200  Module 1 Positioning Chart VLDB Enterprise Workgroup Single user Spreadsheet # Users Cost
System Architecture Bookstore SQL200  Module 1 Access MDB File Server  Architecture Access
System Architecture Bookstore SQL200  Module 1 Oracle DB Visual Basic App Client/Server  Architecture Access  SQL 
System Architecture Bookstore SQL200  Module 1 Oracle DB Browser Web  Architecture Web Server  SQL 
Approaching SQL Relatively simple Two main environments Interactive (This course) Embedded Static (Compiled) Dynamic Bookstore SQL200  Module 1
SQL Standardization ANSI standardization First standard in 1986 SQL 89 SQL 92 SQL 99 Various vendor extensions Microsoft/Sybase: T-SQL Oracle: PL/SQL Bookstore SQL200  Module 1
SQL Conformance Entry Intermediate Advanced Most are at least entry level Bookstore SQL200  Module 1
SQL Statements Data Manipulation Language (DML) Data Control Language (DCL) Data Definition Language (DDL) Note: SQL 99 changes these to seven types Bookstore SQL200  Module 1
SQL DDL Data definition language (DDL) Create, alter, drop, etc. Frequently implemented via various CASE tools: Visio, Embarcadero, ERWin, etc. But very useful for database administration Bookstore SQL200  Module 1
SQL DCL Data Control Language (DDL) Grant Revoke Deny Constraints Bookstore SQL200  Module 1
SQL DML Data Manipulation Language (DML) Select Insert Update Delete Bookstore SQL200  Module 1
SQL Statement Processing Bookstore SQL200  Module 1 Parse Validate Optimize Access Plan Execute
Bookstore Sample Database Before we continue (note: instructor may have already done this)… Load the sample database if you haven’t already Use Access import table feature, or Run SQL script, or Use Access upsizing wizard Bookstore SQL200  Module 1
Text Conventions In Access character strings are normally surrounded by double quotes “ Jones” In an enterprise database such as Oracle or SQL Sever enclose text strings in single quotes ‘ Jones’ Bookstore SQL200  Module 1
Date Conventions In an enterprise database such as Oracle or SQL Sever, enclose dates in single quotes ‘ 2004-12-23’ MySQL ’ 12-23-2004’ SQL Server ’ 23-DEC-04’ Oracle Bookstore SQL200  Module 1
SELECT Bookstore SQL200  Module 1 Basic Syntax ( Projection ): Select <column-list> or <*> From <table-list>
SELECT Bookstore SQL200  Module 1 Basic Example ( Projection ): select   customer_last_name,  customer_street from  customers
MS Access SQL Query Bookstore SQL200  Module 1
Bookstore SQL200  Module 1
SQL Server Query Bookstore SQL200  Module 1
SELECT with Where Clause Bookstore SQL200  Module 1 Example ( Restriction  plus   Projection ): Select <column-list> From <table-list> Where <selection-criteria>;
Comparison Operators < less than > greater than <= less than or equal to >= greater than or equal to <> or != two forms for not equal Bookstore SQL200  Module 1
SELECT with Where Bookstore SQL200  Module 1 Basic Example ( Restriction plus Projection ): select   customer_last_name,  customer_street from  customers where  customer_last_name = ‘Jones’
Select with Where Bookstore SQL200  Module 1
On Your Own Find books written by Mark Twain Show title, publisher, year Bookstore SQL200  Module 1
Complex Predicates Bookstore SQL200  Module 1 Follow normal boolean logic Select   customer_last_name,  customer_street From  customers Where  (customer_last_name = ‘Jones’ or customer_last_name = ‘Smith’)and customer_state=‘NY’
Select with Complex Where Bookstore SQL200  Module 1
Complex Where Result Bookstore SQL200  Module 1
Special Operators Can be used in where clause LIKE IN BETWEEN IS NULL Bookstore SQL200  Module 1
Like (“Wild Card Matches”) ANSI Where customer_last_name like ‘Jo%’ Like ‘Jo_’ Access Where customer_last_name like “Jo*” Like “Jo?” Bookstore SQL200  Module 1
IN Bookstore SQL200  Module 1 Select  * From  customers Where  customer_last_name in (‘Rizzo’, ‘Jones’, ‘Garcia’) The list in parentheses can be replaced by a subquery. We will study this later.
SQL Where Clause with IN Bookstore SQL200  Module 1
IS NULL Bookstore SQL200  Module 1 Select  * From  customers Where  customer_street IS NULL  SQL uses three valued logic. Must use IS NULL to test for unknowns. A null is NOT the same as blank or empty.
On Your Own Find all customers with an address not equal to 4592 Maple Lane Was Peter Johnson selected? Why or why not? Bookstore SQL200  Module 1
BETWEEN Bookstore SQL200  Module 1 Select * From orders Where order_date BETWEEN ‘1-Jan-99’ and ’31-Dec-99’ Note: date formats vary from product to product.
Where with Between Bookstore SQL200  Module 1
Removing Duplicates Bookstore SQL200  Module 1 Select DISTINCT  customer_city From  customers List once each city in which there are customers Removes duplicate rows from result set
Removing Duplicates Bookstore SQL200  Module 1
Sorting – ORDER BY Bookstore SQL200  Module 1 DESC will sort in descending order Basic syntax : Select <column list> From <table list> Where <selection criteria> Order by <column list> [DESC]
Sorting – ORDER BY Bookstore SQL200  Module 1 Select  * From  customers Order by  customer_state, customer_city Example: List all records sorted by state, city
Sorting Results with Order By Bookstore SQL200  Module 1
Selecting Top Records Bookstore SQL200  Module 1 Select Top 5 (or top 25 percent)  Customer_last_name  , contact_zip From  customers Order by customer_zip  desc ; List largest 5 zips or top 25 % of them…
SQL Exercises List all books whose publisher name begins with “H” or “T”; sort by title [hint: use LIKE] List all customers whose last name ends with “S”; sort by state, city, last name Find the order numbers of orders with order dates in 1999; sort by order #. [Hint: use BETWEEN] Find the order numbers and order dates of all orders with a “2” in column 2 of the credit card #; sort by order date descending Bookstore SQL200  Module 1 [end module]
Notes Bookstore SQL200  Module 1

More Related Content

PPT
SQL212.1 Introduction to SQL using Oracle Module 1
PPT
SQL200.1 Module 1
PPTX
Intro to T-SQL - 1st session
PPT
SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2
PPTX
Intro to T-SQL – 2nd session
PDF
Sql tutorial
PDF
Sql tutorial-Structured query language
PPT
Sql server T-sql basics ppt-3
SQL212.1 Introduction to SQL using Oracle Module 1
SQL200.1 Module 1
Intro to T-SQL - 1st session
SQL202.2 Accelerated Introduction to SQL Using SQL Server Module 2
Intro to T-SQL – 2nd session
Sql tutorial
Sql tutorial-Structured query language
Sql server T-sql basics ppt-3

What's hot (19)

PPTX
Sql for biggner
PPT
Sql Pass Through
PPT
SQL Pass Through and the ODBC Interface
PDF
Oracle SQL Basics
PPTX
Structured Query Language (SQL)
PPTX
New T-SQL Features in SQL Server 2012
PDF
SQL Overview
PDF
Introduction to the Structured Query Language SQL
PPTX
Introduction to SQL, SQL*Plus
PPT
Introduction to sql
PPTX
Sql basics
PDF
PostgreSQL Tutorial For Beginners | Edureka
PPTX
Introduction to SQL
PPT
Introduction to structured query language (sql)
PDF
Android de la A a la Z XML Ulises Gonzalez
PPT
Introduction to-sql
PPT
Sql Server 2000
PPTX
Basic SQL and History
PPTX
Introduction to SQL
Sql for biggner
Sql Pass Through
SQL Pass Through and the ODBC Interface
Oracle SQL Basics
Structured Query Language (SQL)
New T-SQL Features in SQL Server 2012
SQL Overview
Introduction to the Structured Query Language SQL
Introduction to SQL, SQL*Plus
Introduction to sql
Sql basics
PostgreSQL Tutorial For Beginners | Edureka
Introduction to SQL
Introduction to structured query language (sql)
Android de la A a la Z XML Ulises Gonzalez
Introduction to-sql
Sql Server 2000
Basic SQL and History
Introduction to SQL
Ad

Viewers also liked (20)

PPT
SQL200.2 Module 2
PPT
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
PDF
Using grouping sets in sql server 2008 tech republic
PPTX
Consultas en MS SQL Server 2012
PPTX
MS SQL SERVER: Creating Views
PDF
Sql db optimization
PPS
Sql xp 04
PPT
Sql tuning guideline
PPTX
Statistics
PPT
e computer notes - Subqueries
PPTX
Sub-queries,Groupby and having in SQL
PPSX
Locking in SQL Server
PPT
Review of SQL
RTF
Triggers-Sequences-SQL
PDF
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
PPT
Lecture 4. MS SQL. DML Triggers
PPTX
Sql query analyzer & maintenance
PPT
Locking And Concurrency
PDF
SQL Server - Using Tools to Analyze Query Performance
SQL200.2 Module 2
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
Using grouping sets in sql server 2008 tech republic
Consultas en MS SQL Server 2012
MS SQL SERVER: Creating Views
Sql db optimization
Sql xp 04
Sql tuning guideline
Statistics
e computer notes - Subqueries
Sub-queries,Groupby and having in SQL
Locking in SQL Server
Review of SQL
Triggers-Sequences-SQL
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Lecture 4. MS SQL. DML Triggers
Sql query analyzer & maintenance
Locking And Concurrency
SQL Server - Using Tools to Analyze Query Performance
Ad

Similar to SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1 (20)

PPT
SQL201S Accelerated Introduction to MySQL Queries
PPT
SQL302 Intermediate SQL Workshop 1
PDF
SQL202 SQL Server SQL Manual
PPT
SQL200.3 Module 3
PDF
SQL201W MySQL SQL Manual
PDF
SQL212 Oracle SQL Manual
PPT
SQL212.3 Introduction to SQL using Oracle Module 3
PDF
SQL302 Intermediate SQL
PPT
SQL302 Intermediate SQL Workshop 2
PPTX
Sql slid
DOC
Module 3
PPT
Chap 7
PPT
PPTX
SQL Query
PPTX
SQL: Structured Query Language
PDF
SQL Commands
PPT
chap 7.ppt(sql).ppt
DOCX
PPTX
SQL(database)
PPT
[PHPUGPH] PHP Roadshow - MySQL
SQL201S Accelerated Introduction to MySQL Queries
SQL302 Intermediate SQL Workshop 1
SQL202 SQL Server SQL Manual
SQL200.3 Module 3
SQL201W MySQL SQL Manual
SQL212 Oracle SQL Manual
SQL212.3 Introduction to SQL using Oracle Module 3
SQL302 Intermediate SQL
SQL302 Intermediate SQL Workshop 2
Sql slid
Module 3
Chap 7
SQL Query
SQL: Structured Query Language
SQL Commands
chap 7.ppt(sql).ppt
SQL(database)
[PHPUGPH] PHP Roadshow - MySQL

More from Dan D'Urso (20)

PPT
LCD201d Database Diagramming with Lucidchart
PPTX
Database Normalization
PPT
VIS201d Visio Database Diagramming
PPT
PRJ101a Project 2013 Accelerated
PPT
PRJ101xl Project Libre Basic Training
PPT
Introduction to coding using Python
PPTX
Stem conference
PDF
SQL200A Microsoft Access SQL Design
PPTX
Microsoft access self joins
PDF
AIN106 Access Reporting and Analysis
PPT
SQL302 Intermediate SQL Workshop 3
PDF
Course Catalog
PDF
AIN100
PPT
SQL206 SQL Median
PDF
AIN102 Microsoft Access Queries
PPT
AIN102S Access string function sample queries
PPT
AIN102.2 Microsoft Access Queries
PPT
AIN102.1 Microsoft Access Queries Module 1
PDF
AIN100B Microsoft Access Level 2
PDF
AMP110 Microsoft Access Macros
LCD201d Database Diagramming with Lucidchart
Database Normalization
VIS201d Visio Database Diagramming
PRJ101a Project 2013 Accelerated
PRJ101xl Project Libre Basic Training
Introduction to coding using Python
Stem conference
SQL200A Microsoft Access SQL Design
Microsoft access self joins
AIN106 Access Reporting and Analysis
SQL302 Intermediate SQL Workshop 3
Course Catalog
AIN100
SQL206 SQL Median
AIN102 Microsoft Access Queries
AIN102S Access string function sample queries
AIN102.2 Microsoft Access Queries
AIN102.1 Microsoft Access Queries Module 1
AIN100B Microsoft Access Level 2
AMP110 Microsoft Access Macros

Recently uploaded (20)

PPTX
Machine Learning_overview_presentation.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Empathic Computing: Creating Shared Understanding
PDF
cuic standard and advanced reporting.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PPT
Teaching material agriculture food technology
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine Learning_overview_presentation.pptx
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
Per capita expenditure prediction using model stacking based on satellite ima...
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MIND Revenue Release Quarter 2 2025 Press Release
Mobile App Security Testing_ A Comprehensive Guide.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
A comparative analysis of optical character recognition models for extracting...
Teaching material agriculture food technology
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing

SQL202.1 Accelerated Introduction to SQL Using SQL Server Module 1

  • 1. SQL200 SQL Programming Based on SQL Clearly Explained by Jan Harrington Module 1 – Relational Database Background, Basic Single Table Retrieval Operations Bookstore SQL200 Module 1
  • 2. Note on SQL200 Slides These slides were originally designed to support the single SQL200 course which was used for any of MS Access, MySQL, Oracle and SQL Server. As such you may see here slides developed in any one of the above products. We are in the process of migrating the Oracle slides and the MS Access slides out into their own slide sets. The SQL200 slides will cover MySQL and SQL Server which are virtually identical for purposes of this course. Bookstore2 SQL200 Module 2
  • 3. Warning! Below are some table name changes to be aware of in doing queries. We have created synonyms so either name should work. Bookstore2 SQL200 Module 2 New Name Old Name Orders Order_filled Order_Lines Orderlines
  • 4. SQL200 Contact Information Bookstore2 SQL200 Module 2 P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address] Copyright 2001-2011. All rights reserved.
  • 5. SQL200 Resources Bookstore database scripts found on box.net at http://tinyurl.com/SQLScripts Slides can be viewed on SlideShare… http://www.slideshare.net/OCDatabases Follow up questions? [email_address] Bookstore SQL212 Module 1
  • 6. SQL Programming Course focus is SQL language Widely used for: Database administration Enterprise application development Data driven web sites A foundation skill for eBusiness and almost all major business applications that use relational databases Bookstore SQL200 Module 1
  • 7. SQL Programming A basic knowledge of query systems, perhaps via MS Access, or some programming knowledge, is desirable We will use GUI tools or SQL Plus almost exclusively Bookstore SQL200 Module 1
  • 8. Relational Database Evolution Based on Codd’s paper Early commercial efforts focused on Unix First mainframe implementation by IBM - precursor to today’s DB2 First PC implementation in early 80’s by Oracle Bookstore SQL200 Module 1
  • 9. Relational Database Basics Storage Databases Tables Rows Columns Indexes Views Cursors Application interfaces Bookstore SQL200 Module 1
  • 10. Bookstore SQL200 Module 1 Relational Database Table
  • 11. Constraints Database Domain Uniqueness Relationship Cardinality 1 to 1 1 to N Other Business Rule Triggers Stored Procedures Bookstore SQL200 Module 1
  • 12. Bookstore SQL200 Module 1 Relational Database with constraints
  • 13. Database Management Systems Bookstore SQL200 Module 1 Positioning Chart VLDB Enterprise Workgroup Single user Spreadsheet # Users Cost
  • 14. System Architecture Bookstore SQL200 Module 1 Access MDB File Server Architecture Access
  • 15. System Architecture Bookstore SQL200 Module 1 Oracle DB Visual Basic App Client/Server Architecture Access  SQL 
  • 16. System Architecture Bookstore SQL200 Module 1 Oracle DB Browser Web Architecture Web Server  SQL 
  • 17. Approaching SQL Relatively simple Two main environments Interactive (This course) Embedded Static (Compiled) Dynamic Bookstore SQL200 Module 1
  • 18. SQL Standardization ANSI standardization First standard in 1986 SQL 89 SQL 92 SQL 99 Various vendor extensions Microsoft/Sybase: T-SQL Oracle: PL/SQL Bookstore SQL200 Module 1
  • 19. SQL Conformance Entry Intermediate Advanced Most are at least entry level Bookstore SQL200 Module 1
  • 20. SQL Statements Data Manipulation Language (DML) Data Control Language (DCL) Data Definition Language (DDL) Note: SQL 99 changes these to seven types Bookstore SQL200 Module 1
  • 21. SQL DDL Data definition language (DDL) Create, alter, drop, etc. Frequently implemented via various CASE tools: Visio, Embarcadero, ERWin, etc. But very useful for database administration Bookstore SQL200 Module 1
  • 22. SQL DCL Data Control Language (DDL) Grant Revoke Deny Constraints Bookstore SQL200 Module 1
  • 23. SQL DML Data Manipulation Language (DML) Select Insert Update Delete Bookstore SQL200 Module 1
  • 24. SQL Statement Processing Bookstore SQL200 Module 1 Parse Validate Optimize Access Plan Execute
  • 25. Bookstore Sample Database Before we continue (note: instructor may have already done this)… Load the sample database if you haven’t already Use Access import table feature, or Run SQL script, or Use Access upsizing wizard Bookstore SQL200 Module 1
  • 26. Text Conventions In Access character strings are normally surrounded by double quotes “ Jones” In an enterprise database such as Oracle or SQL Sever enclose text strings in single quotes ‘ Jones’ Bookstore SQL200 Module 1
  • 27. Date Conventions In an enterprise database such as Oracle or SQL Sever, enclose dates in single quotes ‘ 2004-12-23’ MySQL ’ 12-23-2004’ SQL Server ’ 23-DEC-04’ Oracle Bookstore SQL200 Module 1
  • 28. SELECT Bookstore SQL200 Module 1 Basic Syntax ( Projection ): Select <column-list> or <*> From <table-list>
  • 29. SELECT Bookstore SQL200 Module 1 Basic Example ( Projection ): select customer_last_name, customer_street from customers
  • 30. MS Access SQL Query Bookstore SQL200 Module 1
  • 31. Bookstore SQL200 Module 1
  • 32. SQL Server Query Bookstore SQL200 Module 1
  • 33. SELECT with Where Clause Bookstore SQL200 Module 1 Example ( Restriction plus Projection ): Select <column-list> From <table-list> Where <selection-criteria>;
  • 34. Comparison Operators < less than > greater than <= less than or equal to >= greater than or equal to <> or != two forms for not equal Bookstore SQL200 Module 1
  • 35. SELECT with Where Bookstore SQL200 Module 1 Basic Example ( Restriction plus Projection ): select customer_last_name, customer_street from customers where customer_last_name = ‘Jones’
  • 36. Select with Where Bookstore SQL200 Module 1
  • 37. On Your Own Find books written by Mark Twain Show title, publisher, year Bookstore SQL200 Module 1
  • 38. Complex Predicates Bookstore SQL200 Module 1 Follow normal boolean logic Select customer_last_name, customer_street From customers Where (customer_last_name = ‘Jones’ or customer_last_name = ‘Smith’)and customer_state=‘NY’
  • 39. Select with Complex Where Bookstore SQL200 Module 1
  • 40. Complex Where Result Bookstore SQL200 Module 1
  • 41. Special Operators Can be used in where clause LIKE IN BETWEEN IS NULL Bookstore SQL200 Module 1
  • 42. Like (“Wild Card Matches”) ANSI Where customer_last_name like ‘Jo%’ Like ‘Jo_’ Access Where customer_last_name like “Jo*” Like “Jo?” Bookstore SQL200 Module 1
  • 43. IN Bookstore SQL200 Module 1 Select * From customers Where customer_last_name in (‘Rizzo’, ‘Jones’, ‘Garcia’) The list in parentheses can be replaced by a subquery. We will study this later.
  • 44. SQL Where Clause with IN Bookstore SQL200 Module 1
  • 45. IS NULL Bookstore SQL200 Module 1 Select * From customers Where customer_street IS NULL SQL uses three valued logic. Must use IS NULL to test for unknowns. A null is NOT the same as blank or empty.
  • 46. On Your Own Find all customers with an address not equal to 4592 Maple Lane Was Peter Johnson selected? Why or why not? Bookstore SQL200 Module 1
  • 47. BETWEEN Bookstore SQL200 Module 1 Select * From orders Where order_date BETWEEN ‘1-Jan-99’ and ’31-Dec-99’ Note: date formats vary from product to product.
  • 48. Where with Between Bookstore SQL200 Module 1
  • 49. Removing Duplicates Bookstore SQL200 Module 1 Select DISTINCT customer_city From customers List once each city in which there are customers Removes duplicate rows from result set
  • 50. Removing Duplicates Bookstore SQL200 Module 1
  • 51. Sorting – ORDER BY Bookstore SQL200 Module 1 DESC will sort in descending order Basic syntax : Select <column list> From <table list> Where <selection criteria> Order by <column list> [DESC]
  • 52. Sorting – ORDER BY Bookstore SQL200 Module 1 Select * From customers Order by customer_state, customer_city Example: List all records sorted by state, city
  • 53. Sorting Results with Order By Bookstore SQL200 Module 1
  • 54. Selecting Top Records Bookstore SQL200 Module 1 Select Top 5 (or top 25 percent) Customer_last_name , contact_zip From customers Order by customer_zip desc ; List largest 5 zips or top 25 % of them…
  • 55. SQL Exercises List all books whose publisher name begins with “H” or “T”; sort by title [hint: use LIKE] List all customers whose last name ends with “S”; sort by state, city, last name Find the order numbers of orders with order dates in 1999; sort by order #. [Hint: use BETWEEN] Find the order numbers and order dates of all orders with a “2” in column 2 of the credit card #; sort by order date descending Bookstore SQL200 Module 1 [end module]