Day 4 - Simple Queries & More on Tables

Slides:



Advertisements
Similar presentations
Introduction to SQL, OleDB interface to Access from VB.NET.
Advertisements

CSC271 Database Systems Lecture # 13. Summary: Previous Lecture  Grouping through GROUP BY clause  Restricted groupings  Subqueries  Multi-Table queries.
M ATH IN SQL. 222 A GGREGATION O PERATORS Operators on sets of tuples. Significant extension of relational algebra. SUM ( [DISTINCT] A): the sum of all.
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
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.
Chapter 6 SQL: Data Manipulation Cont’d. 2 ANY and ALL u ANY and ALL used with subqueries that produce single column of numbers u ALL –Condition only.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
SQL 資料庫查詢語言 取材自 EIS, 3 rd edition By Dunn et al..
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Banner and the SQL Select Statement: Part Four (Multiple Connected Select Statements) Mark Holliday Department of Mathematics and Computer Science Western.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Chapter 6 SQL: Data Manipulation (Advanced Commands) Pearson Education © 2009.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
DAT602 Database Application Development Lecture 3 Review of SQL Language.
4a. Structured Query Language - SELECT Statement Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
Working with Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
SQL: Single Table Queries SELECT FROM WHERE ORDER D. Christozov / G.Tuparov INF 280 Database Systems: Single Table Queries 1.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
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.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
1 SQL Chapter 9 – 8 th edition With help from Chapter 2 – 10 th edition.
Day 5 - More Complexity With Queries Explanation of JOIN & Examples Explanation of JOIN & Examples Explanation & Examples of Aggregation Explanation &
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
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.
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
IFS180 Intro. to Data Management Chapter 10 - Unions.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
References: Text Chapters 8 and 9
Basic select statement
Database Systems: Design, Implementation, and Management Tenth Edition
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
JDBC.
Structured Query Language (SQL) William Klingelsmith
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Chapter Name SQL: Data Manipulation
JOINS (Joinining multiple tables)
SQL LANGUAGE and Relational Data Model TUTORIAL
The Relational Model Textbook /7/2018.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Chapter 7 Most important: 7.2
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Databases & Consistency
SQL.
Projecting output in MySql
Database Systems: Design, Implementation, and Management Tenth Edition
Manipulating Data Lesson 3.
JOINS (Joinining multiple tables)
SQL: Structured Query Language
Presentation transcript:

Day 4 - Simple Queries & More on Tables What is a query in MySQL? Basic Format of a Query More Actions on Tables Via Queries

Day 4 - Simple Queries & More on Tables What is a query in MySQL? SQL = Structured Query Language MySQL is based on the ideas of Relational Algebra and Boyce Codd Normal Form (BCNF). A query is basically a formatted question to get meaningful information out of a DB. CSE 498 Day 4 - Simple Queries & More on Tables

Day 4 - Simple Queries & More on Tables Basic Format of a Query Basic queries have three parts... SELECT <column_name> FROM <table_name(s)> WHERE <argument> SELECT allows you to get particular columns of information in the output of the query. SELECT * will select all the columns available. FROM selects the table(s) that the query is going to use to produce the resulting information. WHERE is a TRUE/FALSE resulting clause. Only sets of information that appear as true will be included in the result table. A WHERE clause is not mandatory. CSE 498 Day 4 - Simple Queries & More on Tables

Example DB Schema: Movie DB For this lecture, we are going to use the movie DB table ‘Customer’ for the example. The table for customer has the following format. Customer (CustID, LastName, FirstName, Age, Address) CSE 498 Day 4 - Simple Queries & More on Tables

Querying by an Attribute Allows us to cut down the amount of table rows in a result query. Accomplished by writing an argument in the WHERE clause. Example: What people have the last name ‘Lee’? SELECT * FROM Customer C WHERE C.LastName = “Lee” CSE 498 Day 4 - Simple Queries & More on Tables

Day 4 - Simple Queries & More on Tables Querying by a Column Allows us to cut down the amount of table columns in a result query. Accomplished by picking columns in the select clause. Example: Give me the first names of the people who share the last name ‘Lee’? SELECT C.FirstName FROM Customer C WHERE C.LastName = “Lee” CSE 498 Day 4 - Simple Queries & More on Tables

Duplicate Information Problem Cross referencing table information or just cutting down the number of columns you view can produce duplicate result information. Duplicates can be removed by using the word DISTINCT in the SELECT clause. This will make sure that there is only one instance of a given column in the result. Example: What are all the last names of the customers? SELECT DISTINCT C.LastName FROM Customer C CSE 498 Day 4 - Simple Queries & More on Tables

Day 4 - Simple Queries & More on Tables Sorting Information Data is often added to a DB in random order. Thus, getting an ordered list can be a pain if you have to do it on your own. SQL gives you the command ORDER BY that follows the WHERE clause. This command is defaulted to order things in descending order. Example: Give me an ordered list of the customers’ last names. SELECT DISTINCT C.LastName FROM Customer C ORDER BY C.LastName CSE 498 Day 4 - Simple Queries & More on Tables

Day 4 - Simple Queries & More on Tables Grouping Information Sometimes, it is necessary to group similar items together. The GROUP BY command groups items together into bunches. This command follows the WHERE clause... This is often used with a HAVING clause. CSE 498 Day 4 - Simple Queries & More on Tables

Day 4 - Simple Queries & More on Tables The HAVING clause The HAVING clause is often used with aggregate functions. Aggregate functions are explained on Day 5 along with JOIN. The HAVING clause is a way to isolate groups of information. Refer back to this example later... Example: What ages of customers have more than 2 people in their bracket? SELECT C.Age FROM Customer C GROUP BY C.Age HAVING COUNT(C.Age) > 2; CSE 498 Day 4 - Simple Queries & More on Tables

Day 4 - Simple Queries & More on Tables AS command The AS command allows to to rename relational sets or column names as necessary… Example: Give me an ordered list of the customers’ last names. SELECT DISTINCT C.LastName AS Cust_Last_Name FROM Customer C ORDER BY C.LastName This query would return the result set... Cust_Last_Name Alway Ammerman Becker CSE 498 Day 4 - Simple Queries & More on Tables