Writing Advanced SQL Queries BKF05 Liz Lucchese. Agenda  SQL revealed  What is it and why should I care?  Advanced query interface  So, how do I use.

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Advertisements

Chapter 4 Joining Multiple Tables
Query Methods (SQL). What is SQL A programming language for databases. SQL (structured Query Language) It allows you add, edit, delete and run queries.
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Murach's MySQL, C3© 2012, Mike Murach & Associates, Inc.Slide 1.
{ Dystopian Database A helpful supplement for Goodread’s list of Young Adult Dystopian titles.
ISMT221 Information Systems Analysis and Design Prototyping with MS Access Lab 6 Tony Tam.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
Introduction to Structured Query Language (SQL)
Some Introductory Programming 1. Structured Query Language - used for queries. - a standard database product. 2. Visual Basic for Applications - use of.
Interpreting SQL Code. SQL (The language used to query a database) S is used to specify the you want to include. F is used to specify the the selected.
Advanced SQL SMSU Computer Services Short Course.
Session-01. Hibernate Framework ? Why we use Hibernate ?
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen.
Introduction to XML BKF04 Brian Ciccolo. Agenda XML revealed What is it and why should I care? Syntax semantics Elements and tags and attributes, oh my!
Presentation Handout EDBA – Module 8 Information Technology 21 st December 2014 By K.M.Prashanthan.
Component 4/Unit 6f Topic VI: Create simple querying statements for the database The SELECT statement Clauses Functions Joins Subqueries Data manipulation.
10/31/2012ISC239 Isabelle Bichindaritz1 SQL Graphical Queries Design Query By Example.
Using Special Operators (LIKE and IN)
1 Agenda for Class 03/07/2006  Learn to simplify queries for complex questions through the use of views.  Concept of a view.  Syntax to create and access.
Week 10 Quiz 9 Answers Group 28 Christine Hallstrom Deena Phadnis.
Component 4/Unit 6c Topic III Structured Query Language Background information What can SQL do? How is SQL executed? SQL statement characteristics What.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
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.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Indexes and Views Unit 7.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
© Jalal Kawash Database Queries Peeking into Computer Science.
Mining real world data RDBMS and SQL. Index RDBMS introduction SQL (Structured Query language)
1 Announcements Reading for next week: Chapter 4 Your first homework will be assigned as soon as your database accounts have been set up.  Expect an .
DAY 21: ACCESS CHAPTER 6 & 7 Tazin Afrin October 31,
INFANL01-3 ANALYSE 3 WEEK 3 March 2015 Institute voor Communication, Media en Informatietechnology.
WEEK# 12 Haifa Abulaiha November 02,
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Structured Query Language used for defining and manipulating data in Relational DBs aimed at: –reducing training costs –increasing productivity –improve.
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.
The data in the table.. Starting a query. Two criteria in an AND relationship.
DBM 384 Week 2 DQ 1 Check this A+ tutorial guideline at 384/DBM-384-Week-2-DQ-1 Explain how Structured Query Language.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
More SQL: Complex Queries,
MySQL Subquery Source: Dev.MySql.com
Multiplication table. x
Database Systems: Design, Implementation, and Management Tenth Edition
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Using SQL to Prepare Data for Analysis
Data Manipulation Language Bag. 3
SQL – Entire Select.
Chapter 4 Summary Query.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Database systems Lecture 3 – SQL + CRUD
Access: SQL Participation Project
Using Subqueries to Solve Queries
Structured Query Language – The Fundamentals
Convert (flatten) IATI XML file to CSV file(s) using XQUERY
AST Based Sequence to Sequence Natural Language Question to SQL Method
Navigating Your GP Data
Introduction to Database
Databases Continued 10/18/05.
Database Systems: Design, Implementation, and Management Tenth Edition
Required queries FdSc inICT Module 107.
Database SQL.
Tutorial 9 Using Action Queries and Advanced Table Relationships
SQL Tutorial Basic SQL Commands
Presentation transcript:

Writing Advanced SQL Queries BKF05 Liz Lucchese

Agenda  SQL revealed  What is it and why should I care?  Advanced query interface  So, how do I use this thing?  Recipes for success  Real world examples to learn syntax

SQL Revealed What is it? Structured Query Language A standardized way to query a database Why should I care? It’s used in advanced queries. It’s easy to learn. It’s fun!

Anatomy of a SELECT Statement SELECT * FROM STUDENT WHERE STD_YOG = 2007 ORDER BY STD_NAME_VIEW

Advanced Query Interface WHERE STD_YOG = 2007 SELECT * FROM STUDENT

Multiple Criteria WHERE STD_NAME_VIEW LIKE ‘A%’ AND STD_GRADE_LEVEL IN (‘01’,‘02’,‘03’) SELECT * FROM STUDENT

Parentheses WHERE (STD_YOG = 2007 AND STD_GRADE_LEVEL <> ‘12’) OR (STD_YOG = 2008 AND STD_GRADE_LEVEL <> ‘11’) OR (STD_YOG = 2009 AND STD_GRADE_LEVEL <> ‘10’)... SELECT * FROM STUDENT

Multiple Tables INNER JOIN PERSON ON PSN_OID = STD_PSN_OID WHERE PSN_DOB > ‘ ’ AND PSN_DOB <= ‘ ’ SELECT * FROM STUDENT

Nested Query (version 1) WHERE STD_OID NOT IN (SELECT CTJ_STD_OID FROM STUDENT_CONTACT) SELECT * FROM STUDENT

Nested Query (version 2) WHERE NOT EXISTS (SELECT CTJ_STD_OID FROM STUDENT_CONTACT WHERE STD_OID = CTJ_STD_OID) SELECT * FROM STUDENT

Multiple Nested Queries WHERE STD_OID IN (SELECT REQ_STD_OID FROM STUDENT_COURSE_REQUEST INNER JOIN COURSE_SCHOOL ON CSK_OID = REQ_CSK_OID INNER JOIN DISTRICT_SCHOOL_YEAR_CONTEXT ON CTX_OID = REQ_CTX_OID WHERE CSK_COURSE_NUMBER IN (‘101’,‘102’,‘103’) AND CTX_SCHOOL_YEAR = 2008) AND STD_OID NOT IN (SELECT REQ_STD_OID FROM STUDENT_COURSE_REQUEST INNER JOIN COURSE_SCHOOL ON CSK_OID = REQ_CSK_OID INNER JOIN DISTRICT_SCHOOL_YEAR_CONTEXT ON CTX_OID = REQ_CTX_OID WHERE CSK_COURSE_NUMBER = ‘202’ AND CTX_SCHOOL_YEAR = 2008) SELECT * FROM STUDENT

Aggregate Query WHERE STD_OID IN (SELECT ATT_STD_OID FROM STUDENT_ATTENDANCE WHERE ATT_DATE > ‘ ’ AND ATT_DATE < ‘ ’ AND ATT_ABSENT_IND = ‘1’ GROUP BY ATT_STD_OID HAVING COUNT(*) > 5) SELECT * FROM STUDENT

Extras W3Schools SQL Tutorial SQLzoo.net

Thank you.