Select Statement IT 350. Select Statement SELECT statement is what we use to choose, or select, the data that we want returned from the database to our.

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

WHERE Clause Chapter 2. Objectives Limit rows by using a WHERE clause Use the LIKE operator Effect of NULL values Use compound conditions Use the BETWEEN.
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
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.
Restricting and Sorting Data. Consider the table employee(employee_id,last_name,job_id, department_id ) assume that you want to display all the employees.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Structured Query Language Part I Chapter Three CIS 218.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
Computer Science 101 Web Access to Databases SQL – Extended Form.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Download three SQL script files from wiki page.
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.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
 The WHERE clause, also called the predicate, provides the power to narrow down the scope of the data retrieved.  Comparison Operators Comparison OperatorDefinition.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
Restricting and Sorting Data. ◦ Limiting rows with:  The WHERE clause  The comparison conditions using =,
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
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
SQL Data Manipulation II Chapter 5 CIS 458 Sungchul Hong.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
Lab_03: Basic SQL.
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
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.
Oracle 11g DATABASE DEVELOPMENT LAB2. Chapter- 2  These commands, which could be issued from SQL*Plus or SQL Developer,  will make it possible to log.
SQL SELECT Getting Data from the Database. Basic Format SELECT, FROM WHERE (=, >, LIKE, IN) ORDER BY ; SELECT LastName, FirstName, Phone, City FROM Customer.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
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.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
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.
Limiting Selected Rows. 2-2 Objectives Sort row output using the ORDER BY clause. Sort row output using the ORDER BY clause. Enter search criteria using.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
1 Section 3 - Select Statement u The Select statement allows you to... –Display Data –Specify Selection Criteria –Sort Data –Group Data for reporting –Use.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Restricting and Sorting Data
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
Writing Basic SQL SELECT Statements
 2012 Pearson Education, Inc. All rights reserved.
Basic select statement
ATS Application Programming: Java Programming
JDBC.
Databases Intro (from Deitel)
Restricting and Sorting Data
SQL.
SQL FUNDAMENTALS CDSE Days 2018.
Restricting and Sorting Data
Sirena Hardy HRMS Trainer
Introduction To Structured Query Language (SQL)
Restricting and Sorting Data
Using CASE Value expression
Introduction To Structured Query Language (SQL)
Restricting and Sorting Data
Manipulating Data Lesson 3.
Restricting and Sorting Data
Presentation transcript:

Select Statement IT 350

Select Statement SELECT statement is what we use to choose, or select, the data that we want returned from the database to our application. Common Elements: SELECT FROM WHERE (AND, OR, NOT, BETWEEN, LIKE) ORDER BY

SELECT…FROM Clause Basic SELECT – What Column – What tables(s) All columns SELECT * FROM Employees Certain Columns SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees

WHERE Clause Limits or filters the data by one (or more) conditions that must be met by the selected data. Achieved by the use of relational operators – =,, <>, = – LIKE, IN, BETWEEN, NOT, NOT IN

Employees who live in London SELECT EmployeeID, FirstName, LastName, City FROM Employees WHERE City = 'London' Employees who live anywhere except London SELECT EmployeeID, FirstName, LastName, City FROM Employees WHERE City <> 'London'

A list of employees who where hired on or after a given date SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE HireDate >= '1-july-1993'

AND Multiple criteria is met Example: Date and City SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE (HireDate >= '1-June-1992') AND (City = 'London') Example: Hired between a certain date SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE (HireDate >= '1-june-1992') AND (HireDate <= '15- december-1993')

BETWEEN BETWEEN operator checks to see if a value is between two values (including equality on both ends) SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE HireDate BETWEEN '1-june-1992' AND '15- december-1993'

NOT Returns opposite of mentioned criteria Example: NOT BETWEEN SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE HireDate NOT BETWEEN '1-june-1992' AND '15-december-1993'

OR Multiple Values SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE City = 'London' OR City = 'Seattle'

IN and NOT IN List of multiple values IN Example: SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE City IN ('Seattle', 'Tacoma', 'Redmond') NOT IN Example: SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE City NOT IN ('Seattle', 'Tacoma', 'Redmond')

LIKE LIKE operator allows us to perform basic pattern-matching using wildcard characters WildcardDescription _ (underscore)matches any single character %matches a string of one or more characters [ ] matches any single character within the specified range (e.g. [a-f]) or set (e.g. [abcdef]). [^] matches any single character not within the specified range (e.g. [^a-f]) or set (e.g. [^abcdef]).

LIKE Examples WHERE FirstName LIKE '_im' finds all three-letter first names that end with 'im' (e.g. Jim, Tim). WHERE LastName LIKE '%stein' finds all employees whose last name ends with 'stein' WHERE LastName LIKE '%stein%' finds all employees whose last name includes 'stein' anywhere in the name. WHERE FirstName LIKE '[JT]im' finds three-letter first names that end with 'im' and begin with either 'J' or 'T' (that is, only Jim and Tim) WHERE LastName LIKE 'm[^c]%' finds all last names beginning with 'm' where the following (second) letter is not 'c'.

ORDER BY Order in which the rows appear—sorting the data SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees ORDER BY City

ASC, DESC SELECT EmployeeID, FirstName, LastName, HireDate, Country, City FROM Employees ORDER BY Country, City DESC SELECT EmployeeID, FirstName, LastName, HireDate, Country, City FROM Employees ORDER BY Country ASC, City DESC SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees ORDER BY Country ASC, City DESC