02 | Querying Tables with SELECT

Slides:



Advertisements
Similar presentations
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
1 SQL (Simple Query Language). 2 Query Components A query can contain the following clauses –select –from –where –group by –having –order by Only select.
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.
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Microsoft Access 2010 Chapter 7 Using SQL.
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.
02 | Advanced SELECT Statements Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
IFS Intro. to Data Management Chapter 6 Filtering your data.
 The WHERE clause, also called the predicate, provides the power to narrow down the scope of the data retrieved.  Comparison Operators Comparison OperatorDefinition.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
Chapter 3 Single-Table Queries
SQL/lesson 2/Slide 1 of 45 Retrieving Result Sets Objectives In this lesson, you will learn to: * Use wildcards * Use the IS NULL and IS NOT NULL keywords.
Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
SQL (DDL & DML Commands)
Chapter 11 – Data Manipulation: Relational Algebra and SQL1 Unit 7: Data Manipulation: Relational Algebra and SQL IT238: Data Modeling and Database Design.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
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.
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.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
Selecting Data Database Administration Fundamentals LESSON 3.1a.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Module 2: Querying and Filtering Data. Using the SELECT Statement Filtering Data Working with NULL Values Formatting Result Sets Performance Considerations.
Writing Basic SQL SELECT Statements Lecture
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.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
Querying with Transact-SQL
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Writing Basic SQL SELECT Statements
02 | Advanced SELECT Statements
Sorting and Filtering Data
10 | Programming with Transact-SQL
09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
05 | Using Functions and Aggregating Data
03 | Querying Multiple Tables with Joins
Sorting and Filtering Data
SQL FUNDAMENTALS CDSE Days 2018.
06 | Using Subqueries and APPLY
04 | Using Set Operators Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
09 | Modifying Data Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
Writing SELECT Queries
02 | Querying Tables with SELECT
Restricting and Sorting Data
CS4222 Principles of Database System
Writing Basic SQL SELECT Statements
Introduction To Structured Query Language (SQL)
Restricting and Sorting Data
Shelly Cashman: Microsoft Access 2016
Restricting and Sorting Data
Presentation transcript:

02 | Querying Tables with SELECT Graeme Malcolm | Senior Content Developer Geoff Allix | Principal Technologist, Content Master

Module Overview Removing Duplicates Sorting Results Paging Sorted Results Filtering and Using Predicates

Removing Duplicates SELECT ALL SELECT DISTINCT Default behavior includes duplicates SELECT DISTINCT Removes duplicates Color Blue Red Yellow Black SELECT Color FROM Production.Product; Color Blue Red Yellow Black SELECT DISTINCT Color FROM Production.Product;

Sorting Results Use ORDER BY to sort results by one or more columns Aliases created in SELECT clause are visible to ORDER BY You can order by columns in the source that are not included in the SELECT clause You can specify ASC or DESC (ASC is the default) SELECT ProductCategory AS Category, ProductName FROM Production.Product ORDER BY Category, Price DESC;

Limiting Sorted Results TOP allows you to limit the number or percentage of rows returned by a query Works with ORDER BY clause to limit rows by sort order Added to SELECT clause: SELECT TOP (N) | TOP (N) Percent With percent, number of rows rounded up SELECT TOP (N) WITH TIES Retrieve duplicates where applicable (nondeterministic) SELECT TOP 10 ProductName, ListPrice FROM Production.Product ORDER BY ListPrice DESC;

Paging Through Results OFFSET-FETCH is an extension to the ORDER BY clause: Allows filtering a requested range of rows Dependent on ORDER BY clause Provides a mechanism for paging through results Specify number of rows to skip, number of rows to retrieve: ORDER BY <order_by_list> OFFSET <offset_value> ROW(S) FETCH FIRST|NEXT <fetch_value> ROW(S) ONLY

Eliminating Duplicates and Sorting Results

Filtering and Using Predicates Specify predicates in the WHERE clause Predicates and Operators Description = < > Compares values for equality / non-equality. IN Determines whether a specified value matches any value in a subquery or a list. BETWEEN Specifies an inclusive range to test. LIKE Determines whether a specific character string matches a specified pattern, which can include wildcards. AND Combines two Boolean expressions and returns TRUE only when both are TRUE. OR Combines two Boolean expressions and returns TRUE if either is TRUE. NOT Reverses the result of a search condition.

Filtering with Predicates

Querying Tables with SELECT Removing Duplicates Sorting Results Paging Sorted Results Filtering and Using Predicates Lab: Querying Tables with SELECT