Getting to Know SQL. © Jim Hope 2002 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement TRANSFORM.

Slides:



Advertisements
Similar presentations
Database Languages Chapter 7. The Relational Algebra.
Advertisements

Virtual training week 4 structured query language (SQL)
Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
SQL Basics Based on the relational algebra we just learned. Nonprocedural language – what to be done not how Simple, powerful language Used for both data.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Microsoft Access 2010 Chapter 7 Using SQL.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Agenda TMA01 M876 Block 3 – Using SQL Structured Query Language - SQL A non-procedural language to –Create database and relation structures. –Perform.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
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)
DAT602 Database Application Development Lecture 3 Review of SQL Language.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
Getting to Know SQL. © Jim Hope 2004 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement UNION.
An Introduction to SQL For CS Overview of SQL  It is the standard language for relational systems, although imperfect  Supports data definition.
Course title: Database-ii Chap No: 03 “Advanced SQL” Course instructor: ILTAF MEHDI.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
WEEK# 12 Haifa Abulaiha November 02,
Chapter 11 Database and SQL. Flat Files and Databases Flat files Databases Advantages Efficient use of resources Access control Disadvantages Security.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.
April 2002 Information Systems Design John Ogden & John Wordsworth 1 Database Design SQL (1) John Wordsworth Department of Computer Science The University.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
1 Introduction to Database Systems, CS420 SQL JOIN, Group-by and Sub-query Clauses.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Web Systems & Technologies
From: SQL From:
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Structured Query Language
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Structured Query Language (SQL) William Klingelsmith
Web Services שפת SQL כתבה: זהבה יעקובסון ליווי מקצועי : ארז קלר
Introduction To Structured Query Language (SQL)
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Access: SQL Participation Project
Chapter 7 Introduction to Structured Query Language (SQL)
Structured Query Language – The Fundamentals
Introduction To Structured Query Language (SQL)
Structured Query Language
CSC 453 Database Systems Lecture
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Getting to Know SQL

© Jim Hope 2002 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement TRANSFORM statement UNION operation

© Jim Hope 2002 All Rights Reserved Data Definition CREATE TABLE statement CREATE INDEX statement ALTER TABLE statement CONSTRAINT clause DROP statement SELECT... INTO statement

© Jim Hope 2002 All Rights Reserved Example 1 SELECT * FROM people ; Means: Select all the fields (*) for all rows from the table called people

© Jim Hope 2002 All Rights Reserved Example 2 Specify Fields SELECT lastname, firstname FROM people ; Means: Select the fields (lastname and firstname) for all rows from the table called people

© Jim Hope 2002 All Rights Reserved Example 3a Setting the Scope SELECT lastname, firstname, score FROM people WHERE score >=250 Means: Select the fields (lastname, firstname, score) for only rows where the score is greater than or equal to 250

© Jim Hope 2002 All Rights Reserved Example 3b Setting the Scope SELECT lastname, firstname, score FROM people WHERE score >=250 OR score <=100 Means: Select the fields (lastname and firstname, score) for only rows where the score is greater than or equal to 250 or the score is less than or equal to 100

© Jim Hope 2002 All Rights Reserved Example 4a Setting the Order SELECT lastname, firstname FROM people ORDER BY lastname ; Means: Select the fields (lastname and firstname) for all rows from the table called people, in alphabetical (ascending) order by the values in the lastname field.

© Jim Hope 2002 All Rights Reserved Example 4b Setting the Order SELECT lastname, firstname FROM people ORDER BY lastname, firstname ; Means: Select the fields (lastname and firstname) for all rows from the table called people, in alphabetical (ascending) order by the values in the lastname field. If there are duplicates – use the firstname (ascending)

© Jim Hope 2002 All Rights Reserved Example 4c Setting the Order SELECT lastname, firstname, score FROM people ORDER BY score DESC, lastname, firstname; Means: Select the fields (lastname and firstname) for all rows from the table called people, in (descending) order by the values in the score field.

© Jim Hope 2002 All Rights Reserved Example 4d Setting the Order – you try SELECT lastname, firstname, score FROM people ORDER BY score DESC What would you do if you wanted to see duplicate scores presented alphabetically

© Jim Hope 2002 All Rights Reserved Example 5a Putting things together SELECT lastname, firstname, score, FROM people WHERE score >=290 or score <=100 ORDER BY score DESC What is this doing, and what else would you add?

© Jim Hope 2002 All Rights Reserved Example 5b Putting more things together SELECT lastname, firstname, score,city FROM people WHERE (score >=290 or score "Surrey" ORDER BY score DESC What is this doing, and what else would you add?

© Jim Hope 2002 All Rights Reserved Example 5c More Scoping with IN SELECT lastname, firstname, score FROM people WHERE lastname IN ("Bundy", "Simpson", "Petrie"); (much better than… WHERE lastname = “Bundy” OR lastname = “Simpson” OR lastname = “Petrie”

© Jim Hope 2002 All Rights Reserved Example 5d Whatnot SELECT lastname, firstname, score FROM people WHERE lastname NOT IN ("Bundy", "Simpson", "Petrie"); Try this one

© Jim Hope 2002 All Rights Reserved Example 6a Counting SELECT count(*) FROM people

© Jim Hope 2002 All Rights Reserved Example 6b Counting SELECT count(*) FROM people WHERE score <100

© Jim Hope 2002 All Rights Reserved Example 7 Wildcards SELECT lastname, firstname FROM people WHERE lastname like 'b*‘ (WHERE lastname like 'b%‘)

© Jim Hope 2002 All Rights Reserved Example 8 You can do math? SELECT lastname, firstname, score, score +10 as bigscore FROM people ORDER BY score DESC

© Jim Hope 2002 All Rights Reserved Example 9 Create an Alias SELECT lastname +", " + firstname as fullname FROM people ORDER BY lastname, firstname

© Jim Hope 2002 All Rights Reserved Example 10a Max & Min SELECT max (score) FROM people SELECT min (score) FROM people

© Jim Hope 2002 All Rights Reserved Example 10b Max again SELECT lastname, firstname, score FROM people WHERE score = (SELECT max(score) FROM people); This is a subquery

© Jim Hope 2002 All Rights Reserved Example 11 Keeping things DISTINCT SELECT DISTINCT city FROM people;

© Jim Hope 2002 All Rights Reserved Example 12a More than one table SELECT lastname, firstname, score, [show name] FROM people, show ; This creates a Cartesian Product

© Jim Hope 2002 All Rights Reserved Example 12b More than one table SELECT lastname, firstname, score, [show name] FROM people, show WHERE people.show=show.show ;

© Jim Hope 2002 All Rights Reserved Example 12c Using Join SELECT lastname, firstname, score, [show name] FROM People INNER JOIN Show ON people.show = show.show ; FROM people, show WHERE people.show=show.show ;

© Jim Hope 2002 All Rights Reserved Example 12c Using Join SELECT lastname, firstname, score, [show name] FROM People INNER JOIN Show ON people.show = show.show ;

© Jim Hope 2002 All Rights Reserved Example 12d Using Left Join SELECT lastname, firstname, score, [show name] FROM People Left JOIN Show ON people.show = show.show ;

© Jim Hope 2002 All Rights Reserved Example 12e Using Right Join SELECT lastname, firstname, score, [show name] FROM People Right JOIN Show ON people.show = show.show ;

© Jim Hope 2002 All Rights Reserved That’s enough of that