Lecture 11 SQL. Agenda SQL Select statement WHERE clause BindingSource filtering.

Slides:



Advertisements
Similar presentations
CSC271 Database Systems Lecture # 11.
Advertisements

Chapter 6 SQL: Data Manipulation Pearson Education © 2009.
CSC271 Database Systems Lecture # 13. Summary: Previous Lecture  Grouping through GROUP BY clause  Restricted groupings  Subqueries  Multi-Table queries.
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Chapter 6 SQL: Data Manipulation. 2 Objectives of SQL u Database language should allow user to: –create database and relation structures –perform insertion,
© Pearson Education Limited, Chapter 3 SQL and QBE Transparencies.
1 Minggu 4, Pertemuan 7 SQL: Data Manipulation Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Ceng 356-Lab2. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort the.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
IFS Intro. to Data Management Chapter 6 Filtering your data.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
CSC271 Database Systems Lecture # 10.
Agenda TMA01 M876 Block 3 – Using SQL Structured Query Language - SQL A non-procedural language to –Create database and relation structures. –Perform.
Data Manipulation Using MySQL tMyn1 Data Manipulation Using MySQL Ideally, a database language should allow a user to: –Create the database and relation.
SQL: Overview SQL Overview © Pearson Education Limited 1995, 2005.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
10/15/2012ISC239 Isabelle Bichindaritz1 SQL Queries.
CSC271 Database Systems Lecture # 12. Summary: Previous Lecture  Row selection using WHERE clause  WHERE clause and search conditions  Sorting results.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
Chapter 7 SQL: Data Manipulation Chapter#6 in the text book Pearson Education © 2009.
Chapter 7 Introduction to SQL(Wk11_12) © Pearson Education Limited 1995, 2005.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
SQL Data Manipulation II Chapter 5 CIS 458 Sungchul Hong.
Chapter 5 SQL Data Manipulation Language Chapter 5 in Textbook.
Chapter 5 SQL: Data Manipulation © Pearson Education Limited 1995, 2005.
SQL: Data Manipulation I Chapter 5 CIS 458 Sungchul Hong.
Chapter 5 SQL: Data Manipulation. 2 Chapter - Objectives u Purpose and importance of SQL. u How to retrieve data from database using SELECT and: –Use.
Chapter 7 SQL: Data Manipulation Chapter #6 in the textbook Pearson Education © 2009.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
IST 210 SQL Todd Bacastow IST 210: Organization of Data.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Structured Query Language
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
SQL : Data Manipulation Pertemuan 09 s/d 12 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
IST 210 More SQL Todd Bacastow IST 210: Organization of Data.
Chapter 6 SQL – Data Manipulation Pearson Education © 2014.
SQL and QBE Transparencies. ©Pearson Education 2009 Chapter 3 - Objectives Purpose and importance of SQL, the main language for querying relational databases.
SQL: Data Manipulation. Objectives Describe the purpose and importance of SQL. Demonstrate how to retrieve data from database using SELECT and: ▫Use compound.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
SQL: Additional Notes. 2 Example 5.3 Use of DISTINCT List the property numbers of all properties that have been viewed. SELECT propertyNo FROM Viewing;
SQL - DML Review with an example. 2 SELECT Statement SELECT [DISTINCT | ALL] {* | [columnExpression [AS newName]] [,...] } FROMTableName [alias] [,...]
Chapter 6 SQL: Data Manipulation Pearson Education © 2009.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
Teacher Workshop Database Design Pearson Education © 2014.
Chapter 11 SQL: Data Manipulation
Tahun : <<2007>> Versi : <<2/1>>
Chapter Name SQL: Data Manipulation
Chapter Name SQL: Data Manipulation
Data Manipulation Language
SQL – Data Manipulation
Introduction to SQL Chapter 3.
Chapter Name SQL: Data Manipulation Chapter #6 in the textbook
STRUCTURED QUERY LANGUAGE
© Pearson Education Limited, 2004
Chapter Name SQL: Data Manipulation Chapter #6 in the textbook
Restricting and Sorting Data
Chapter Name SQL: Data Manipulation
Chapter Name SQL: Data Manipulation
SQL – Data Manipulation
Chapter Name SQL: Data Manipulation
Chapter Name SQL: Data Manipulation Transparencies
Chapter Name SQL: Data Manipulation Transparencies
Chapter Name SQL: Data Manipulation
Presentation transcript:

Lecture 11 SQL

Agenda SQL Select statement WHERE clause BindingSource filtering

Writing SQL Commands SQL statement consists of reserved words and user-defined words. Reserved words are a fixed part of SQL and must be spelt exactly as required and cannot be split across lines. User-defined words are made up by user and represent names of various database objects such as relations, columns, views. Most components of an SQL statement are case insensitive, except for literal character data.

SELECT Statement SELECT [DISTINCT | ALL] {* | [columnExpression [AS newName]] [,...] } FROMTableName [alias] [,...] [WHERE condition] [GROUP BYcolumnList] [HAVINGcondition] [ORDER BYcolumnList]

SELECT Statement SELECT Specifies which columns are to appear in output. FROM Specifies table(s) to be used. WHERE Filters rows. GROUP BY Forms groups of rows with same column value. HAVING Filters groups subject to some condition. ORDER BY Specifies the order of the output.

SELECT Statement Order of the clauses cannot be changed. Only SELECT and FROM are mandatory.

Comparison Search Condition List all staff with a salary greater than 10,000. SELECT staffNo, fName, lName, position, salary FROM Staff WHERE salary > 10000

Comparison Search Condition

Compound Comparison Search Condition List addresses of all branch offices in London or Glasgow. SELECT * FROM Branch WHERE city = ‘London’ OR city = ‘Glasgow’

Range Search Condition List all staff with a salary between 20,000 and 30,000. SELECT staffNo, fName, lName, position, salary FROM Staff WHERE salary BETWEEN AND BETWEEN test includes the endpoints of range.

Range Search Condition

Also a negated version NOT BETWEEN. BETWEEN does not add much to SQL’s expressive power. Could also write: SELECT staffNo, fName, lName, position, salary FROM Staff WHERE salary>=20000 AND salary <= Useful, though, for a range of values.

Set Membership (IN) List all managers and supervisors. SELECT staffNo, fName, lName, position FROM Staff WHERE position IN (‘Manager’, ‘Supervisor’);

Set Membership There is a negated version (NOT IN). IN does not add much to SQL’s expressive power. Could have expressed this as: SELECT staffNo, fName, lName, position FROM Staff WHERE position=‘Manager’ OR position=‘Supervisor’ IN is more efficient when set contains many values.

Pattern Matching (LIKE) Find all owners with the string ‘Glasgow’ in their address. SELECT clientNo, fName, lName, address, telNo FROM PrivateOwner WHERE address LIKE ‘%Glasgow%’

Pattern Matching

SQL has two special pattern matching symbols:  %: sequence of zero or more characters;  _ (underscore): any single character. LIKE ‘%Glasgow%’ means a sequence of characters of any length containing “Glasgow”

BindingSource filtering Applied to BindingSource only Use Filter property No need for WHERE keyword: TbTeacherBindingSource.Filter = “first_name = ‘Anna’” Set to “” to show all data: TbTeacherBindingSource.Filter = “”

The End