SQL Statements: Queries. Relational Databases Relational Databases organize the data in tables with rows and columns. This is similar to the organization.

Slides:



Advertisements
Similar presentations
Virtual training week 4 structured query language (SQL)
Advertisements

Session 4 SQL Structured Query Language. SQL Modes of use –Interactive –Embedded Purpose –Create database –Create, Read, Update, Delete.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
Introduction to Structured Query Language (SQL)
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
Introduction to Structured Query Language (SQL)
Microsoft Access 2010 Chapter 7 Using SQL.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Working with Tables: Data Management and Retrieval Dr. Bernard Chen Ph.D. University of Central Arkansas.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
Introduction to SQL Steve Perry
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
SQL (DDL & DML Commands)
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Single-Table Queries 1: Basics CS 320 Online. Review: SQL Command Types  Data Definition Language (DDL)  Used to create and modify database objects.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 Information Retrieval and Use (IRU) CE An Introduction To SQL Part 1.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
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.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Labtest.ASP Notes. INSERT STATUS INSERT STATUS
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
SQL Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 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 SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Database Access with SQL
Chapter 5 Introduction to SQL.
Query Methods Where Clauses Start ….
Insert, Update and the rest…
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
SQL Implementation & Administration
ATS Application Programming: Java Programming
Introduction to Oracle9i: SQL
SQL Tutorial.
CIS16 Application Programming with Visual Basic
Structured Query Language
Database SQL.
Intro to SQL CS-422 Dick Steflik.
Presentation transcript:

SQL Statements: Queries

Relational Databases Relational Databases organize the data in tables with rows and columns. This is similar to the organization of spreadsheets. 111SmithJoe1 112ElSawaJane1 113ChiJill3 114MontiJack1 StudentNo.LastNameFirstNameStatus STUDENT TABLE Row Column

Relational Database Operations. There are three fundamental operations on pre- defined (already created) tables.  Query. Retrieval of data from one or more columns from one or more rows typically based on some condition.  Insert. Insert an entire row with all columns into the table.  Update. Modification of one or more columns from one or more rows typically based on some condition.  Delete. Removal of a row typically based on some condition

Language Note! One confusing term in Relational Database usage is update. When used as a general term it means any operation that can modify the state of a table. The means that SQL UPDATE statements, SQL INSERT statements and SQL DELETE statements can be considered as updates (in a general sense). As a results statements that alter pre-defined tables are divided into two categories, queries and updates.

Types of Statements. Queries. In SQL these are executed using the SELECT statements. Updates. In SQL these are executed typically using INSERT to add entire rows to a table or UPDATE to modify columns in pre-existing rows in a table or DELETE to delete entire rows from a table.

Querying a Database You can retrieve information from a database by executing a query. Queries involve requesting the return of one or all columns for each row that matches a condition. A query returns a result set which is a collection of rows with each row containing only the columns requested by query.

The Select Statement A select statement is used to query a database. Select statements typically (but not always) require:  Which columns in a table or tables you wish to retrieve.  Which tables you will retrieve the information from.  Any special conditions you may attach to the query. Select statements must end with a semi-colon.

SELECT Statement Select Lastname,Firstname From Student Where Status=1; Columns to Retrieve Table to Query Special Conditions to refine search.

SELECT Statement Select * From Student; Retrieve all columns Table to Query No Condition is supplied so columns from ALL rows in Student will be returned…i.e. unconditional query.

Special Syntax Notes. Enclose string constants used in comparisons in single quotes not double quotes.  Select * from tablename where sfield=‘Fred’; Numeric constants do not need quotes.  Select * from tablename where numfield=27;

Simple Queries/No Conditions 111SmithJoe1 112ElSawaJane1 113ChiJill3 114MontiJack1 StudentNo.LastNameFirstNameStatus STUDENT TABLE Select LastName,FirstName from Student; LastNameFirstName 4 Two-Column Rows in the Result Set SmithJoe ElSawaJane ChiJill MontiJack

Simple Queries w/Conditions 111SmithJoe1 112ElSawaJane1 113ChiJill3 114MontiJack1 StudentNo.LastNameFirstNameStatus STUDENT TABLE Select LastName,Status from Student Where Status=1 ; LastNameStatus 3 Two-Column Rows in the Result Set Smith1 ElSawa1 Monti1

Simple Queries w/ Compound Condition 111SmithJoe1 112ElSawaJane1 113ChiJill3 114MontiJack1 StudentNo.LastNameFirstNameStatus STUDENT TABLE Select LastName,Status from Student Where Status=2; LastNameStatus No rows returned that satisfy condition. NULL SET

Conditional Operations -Conventional ExpressionEvaluation A = BTrue if A equals B A != BTrue if A does not equal B A <= BTrue if A is less than or equal to B A > BTrue if A is greater than or equal to B A < BTrue if A is less than B A > BTrue if A is greater than B

Conditional Operations - Special ExpressionEvaluation A BTrue if A is equal to B (NULL Safe) A IS NULLTrue if A is NULL A IS NOT NULLTrue if A is not NULL A BETWEEN M AND NTrue if A is between values M and N A NOT BETWEEN M AND NTrue if A is not between values M and N A IN(value, value2,...)True if A is one of the listed values A NOT IN (value, value2,...)True if A is not one of the listed values

Compound Operators. And returns row only if both conditions in compound statement are true. Or returns row if either condition in compound statement is true. You can negate (NOT) a compound condition by enclosing the condition in parentheses.

Simple Queries w/ Compound Condition 111SmithJoe1 112ElSawaJane1 113ChiJill3 114MontiJack1 StudentNo.LastNameFirstNameStatus STUDENT TABLE Select LastName,Status from Student Where Status=1 And FirstName=‘Jane’ ; LastNameStatus 1 Two-Column Row in the Result Set ElSawa1

Simple Queries w/Conditions 111SmithJoe1 112ElSawaJane1 113ChiJill3 114MontiJack1 StudentNo.LastNameFirstNameStatus STUDENT TABLE Select LastName,Status from Student Where Status=3 Or FirstName=‘Jane’ ; LastNameStatus 2 Two-Column Rows in the Result Set ElSawa1 Chi3

Simple Queries w/ Compound Condition 111SmithJoe1 112ElSawaJane1 113ChiJill3 114MontiJack1 STUDENT TABLE Select LastName,Status from Student Where Status=1 And FirstName=‘Jill’ ; LastNameStatus No rows returned that satisfy condition. NULL SET