Lecture 3 Finishing SQL www.Agile1Tech.com.

Slides:



Advertisements
Similar presentations
Advanced SQL (part 1) CS263 Lecture 7.
Advertisements

© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
Beginning SQL Tutorial Author Jay Mussan-Levy. What is SQL?  Structured Query Language  Communicate with databases  Used to created and edit databases.
Introduction to Structured Query Language (SQL)
19-Jun-15 SQL. SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell” is the only correct.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Chapter 7: SQL, the Structured Query Language Soid Quintero & Ervi Bongso CS157B.
Introduction to SQL J.-S. Chou Assistant Professor.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Chapter 3 Single-Table Queries
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
SQL 1: GETTING INFORMATION OUT OF A DATABASE MIS2502 Data Analytics.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
MIS2502: Data Analytics SQL – Getting Information Out of a Database David Schuff
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
SQL SeQueL -Structured Query Language SQL SQL better support for Algebraic operations SQL Post-Relational row and column types,
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
SQL SELECT Getting Data from the Database. Basic Format SELECT, FROM WHERE (=, >, LIKE, IN) ORDER BY ; SELECT LastName, FirstName, Phone, City FROM Customer.
MIS2502: Data Analytics SQL – Getting Information Out of a Database.
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: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
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.
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.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
SQL - Training Rajesh Charles. Agenda (Complete Course) Introduction Testing Methodologies Manual Testing Practical Workshop Automation Testing Practical.
Standard language for querying and manipulating data Structured Query Language Many standards out there: ANSI SQL, SQL92 (a.k.a. SQL2), SQL99 (a.k.a. SQL3),
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
SQL, the Structured Query Language
How to: SQL By: Sam Loch.
SQL Query Getting to the data ……..
Rob Gleasure robgleasure.com
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Relational Database Design
Writing Basic SQL SELECT Statements
Insert, Update and the rest…
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
 2012 Pearson Education, Inc. All rights reserved.
Creating Databases for Web Applications
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.
The Database Exercises Fall, 2009.
CIS 336 Competitive Success/snaptutorial.com
CIS 336 Education for Service-- snaptutorial.com.
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Restricting and Sorting Data
SQL LANGUAGE and Relational Data Model TUTORIAL
Structured Query Language
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Database systems Lecture 3 – SQL + CRUD
Lecture 2 Database & SQL Continued
CMPT 354: Database System I
M1G Introduction to Database Development
Introduction To Structured Query Language (SQL)
Relational Database Design
CSC 453 Database Systems Lecture
Presentation transcript:

Lecture 3 Finishing SQL www.Agile1Tech.com

Quick Recap Constraints Select Operators Not Null, Unique What is a Database schema A Collection of Database Objects associated with ONE database Username. EX – Facebook Personal_Information, Wall_Posts, Friends, Friends_Wall_Posts What are some Datatypes? Go through the Datatypes table to review. EX - String, Number, etc. Select Operators Equal, Not Equal, Greater than, Less than, etc. etc. BETWEEN, LIKE, IN Select Distinct, Wildcards Constraints Not Null, Unique PRIMARY KEY / FOREIGN KEY www.agile1tech.com Zahid Hussin

QUIZ!!! (like I promised) Can a Table have more than one PRIMARY KEY? Can a Table have more than one FOREIGN KEY? What is the difference between COUNT() and COUNT(*) Write a Query to find the FIRST_NAME which starts with the letter “T”. Table name for this Question is “persons” True/False --- A Primary key CAN contain Null Values. True/False --- A Primary key CANNOT contain Unique Values Here is the tough one! ---- Write the line of code which creates the foreign key constraint for a column. www.agile1tech.com Zahid Hussin

HOMEWORK REVIEW ! First we need to create the table which is used in the homework.

HW REVIEW CONT. 1. What Query will confirm 10 records are in the database? 2. Write a query that tells you how many drivers are single drivers? 3. Write a Query that tells you how many drivers are not single drivers? 4. In the front end, you wrote 10 records. For each record a new customer ID is generated. What should your max customer ID be?

HW part 1.5 What is the difference between Count() and Count(*) Which aggregate function gives you the biggest value of a column? If you want to order the table from newest entry to oldest entry, what would be the code for this? 1. Count (Column_name) will count the NON-NULL data in column_name and return that number. 2. Count (*) will count EVERY ROW in the ENTIRE TABLE and return that value.

HW PART 1.5 CONT. 4. Write the code which will help you search for a record that starts or ends with a certain character. 5. Write an SQL query which will help you find a city with ONLY 5 Characters. 6. Write an SQL query to find the first name of employees that start with the letter 'A'.

HW PART 2

HW PART 2 CONT. 1. Write a query to display first name and last name for all employees whose salary is in the range $10,000 through $15,000 I HAD AN ISSUE HERE, there were too many rows and I only wanted to see this answer within the first 10 rows that showed above.

HW PART 2 CONT. 2. Write a query to display the [first name, last name and department ID] of all employees in departments 30 or 100 in descending order by department ID.

HW PART 2 CONT. 3. Write a query to display the first name, last name and hire date for all employees who were hired in 1987. 4. Write a query to display the last names of employees whose names have exactly 6 characters.

HW PART 2 CONT. 5. Write a query to display the first name, last name and salary for all employees whose salary is in the range $10,000 through $15,000 and are in department 30 or 100.

!!!JOINS!!! Imagine that Each table is represented by a circle. THIS IS THE MOST IMPORTANT SQL COMMAND YOU WILL EVER EVER EVER EVER EVER EVER EVER EVER LEARN!!!!!!!!!! An instruction to a database to combine data from MORE THAN ONE TABLE. And then to return some values WHICH FULFILL A SPECIFIC CONDITION. Imagine that Each table is represented by a circle. Then what can we do with these circles? www.agile1tech.com Zahid Hussin

Lets start ! To explain this, I will use 2 basic tables which are easy to understand. Table 1 = people Table 2 = food What does the foreign key signify? What does it do?

First understand Foreign Key Lets put some data into our two tables Why doesn’t this work?

What about NO Foreign key? And now will it work?

YES

JOIN INNER JOIN General Query Example… What if I only want to see the name of the person and the food they like? Introduction to Software Testing (Ch 1) © Ammann & Offutt

INNER JOIN CONT. I want to see which food people like. What about more complex functions?

RIGHT JOIN SAME AS RIGHT OUTER JOIN General Query Someone explain this to me!!!

RIGHT JOIN CONT.

LEFT JOIN SAME AS LEFT OUTER JOIN General Query This should be easier to explain.

LEFT JOIN CONT.