SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Restricting and Sorting Data
Objectives ,[object Object],[object Object],[object Object],[object Object]
Limiting Rows Using a Selection “ retrieve all employees in department 90” EMPLOYEES …
Limiting the Rows Selected ,[object Object],[object Object],SELECT *|{[DISTINCT]  column|expression  [ alias ],...} FROM table [WHERE condition(s) ];
Using the  WHERE  Clause SELECT employee_id, last_name, job_id, department_id FROM  employees WHERE  department_id = 90 ;
Character Strings and Dates ,[object Object],[object Object],[object Object],SELECT last_name, job_id, department_id FROM  employees WHERE  last_name = 'Whalen';
Comparison Conditions Operator = > >= < <= <> Meaning Equal to Greater than  Greater than or equal to  Less than  Less than or equal to Not equal to
Using Comparison Conditions SELECT last_name, salary FROM  employees WHERE  salary <= 3000;
Other Comparison Conditions Operator BETWEEN ...AND... IN(set) LIKE IS NULL Meaning Between two values (inclusive), Match any of a list of values  Match a character pattern  Is a null value
Using the  BETWEEN  Condition ,[object Object],SELECT last_name, salary FROM  employees WHERE  salary BETWEEN 2500 AND 3500; Lower limit Upper limit
Using the  IN  Condition ,[object Object],[object Object],SELECT employee_id, last_name, salary, manager_id FROM  employees WHERE  manager_id IN (100, 101, 201);
Using the  LIKE  Condition ,[object Object],[object Object],[object Object],[object Object],SELECT first_name FROM  employees WHERE first_name LIKE 'S%';
[object Object],[object Object],Using the  LIKE  Condition SELECT last_name FROM  employees WHERE  last_name LIKE '_o%';
Using the  NULL  Conditions ,[object Object],SELECT last_name, manager_id FROM  employees WHERE  manager_id IS NULL;
Logical Conditions Operator AND OR NOT Meaning Returns  TRUE  if  both  component conditions are true Returns  TRUE  if  either  component condition is true Returns  TRUE  if the following  condition is false
Using the  AND  Operator AND  requires both conditions to be true. SELECT employee_id, last_name, job_id, salary FROM  employees WHERE  salary >=10000 AND  job_id LIKE '%MAN%';
Using the  OR  Operator ,[object Object],SELECT employee_id, last_name, job_id, salary FROM  employees WHERE  salary >= 10000 OR  job_id LIKE '%MAN%';
Using the  NOT  Operator SELECT last_name, job_id FROM  employees WHERE  job_id  NOT IN ('IT_PROG', 'ST_CLERK', 'SA_REP');
Rules of Precedence Override rules of precedence by using parentheses. Order Evaluated Operator 1 Arithmetic operators  2 Concatenation operator 3 Comparison conditions 4 IS   [NOT]   NULL ,  LIKE ,  [NOT]   IN 5 [NOT] BETWEEN 6 NOT  logical condition 7 AND  logical condition 8 OR  logical condition
Rules of Precedence SELECT last_name, job_id, salary FROM  employees WHERE  job_id = 'SA_REP' OR  job_id = 'AD_PRES' AND  salary > 15000;
Rules of Precedence SELECT last_name, job_id, salary FROM  employees WHERE  (job_id = 'SA_REP' OR  job_id = 'AD_PRES') AND  salary > 15000; Use parentheses to force priority.
ORDER BY  Clause ,[object Object],[object Object],[object Object],[object Object],SELECT  last_name, job_id, department_id, hire_date FROM  employees ORDER BY hire_date ; …
Sorting in Descending Order SELECT  last_name, job_id, department_id, hire_date FROM  employees ORDER BY hire_date DESC ; …
Sorting by Column Alias SELECT employee_id, last_name, salary*12 annsal FROM  employees ORDER BY annsal; …
[object Object],[object Object],Sorting by Multiple Columns SELECT last_name, department_id, salary FROM  employees ORDER BY department_id, salary DESC; …
Summary SELECT  *|{[DISTINCT]  column|expression  [ alias ],...} FROM  table [WHERE  condition(s) ] [ORDER BY  { column, expr, alias } [ASC|DESC]]; ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Practice 2 Overview ,[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Les07 (using the set operators)
Les07 (using the set operators)Les07 (using the set operators)
Les07 (using the set operators)
Achmad Solichin
 
Dynamic websites lec2
Dynamic websites lec2Dynamic websites lec2
Dynamic websites lec2
Belal Arfa
 

Was ist angesagt? (19)

Les04
Les04Les04
Les04
 
Les07
Les07Les07
Les07
 
75864 sql
75864 sql75864 sql
75864 sql
 
Les07 (using the set operators)
Les07 (using the set operators)Les07 (using the set operators)
Les07 (using the set operators)
 
Dump Answers
Dump AnswersDump Answers
Dump Answers
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 
Lesson02 学会使用WHERE、ORDER BY子句
Lesson02 学会使用WHERE、ORDER BY子句Lesson02 学会使用WHERE、ORDER BY子句
Lesson02 学会使用WHERE、ORDER BY子句
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
Les04
Les04Les04
Les04
 
Using subqueries to solve queries
Using subqueries to solve queriesUsing subqueries to solve queries
Using subqueries to solve queries
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 
Sql queires
Sql queiresSql queires
Sql queires
 
Les04
Les04Les04
Les04
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
1 z0 001
1 z0 0011 z0 001
1 z0 001
 
1 z0 047
1 z0 0471 z0 047
1 z0 047
 
Database systems administration traning 04
Database systems administration traning  04Database systems administration traning  04
Database systems administration traning 04
 
Dynamic websites lec2
Dynamic websites lec2Dynamic websites lec2
Dynamic websites lec2
 
Les06
Les06Les06
Les06
 

Ähnlich wie Les02

Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
Achmad Solichin
 
e computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statementse computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statements
ecomputernotes
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
jhe04
 

Ähnlich wie Les02 (20)

Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
Les02
Les02Les02
Les02
 
Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
Module 3.1.pptx
Module 3.1.pptxModule 3.1.pptx
Module 3.1.pptx
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Les02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.pptLes02 Restricting and Sorting Data using SQL.ppt
Les02 Restricting and Sorting Data using SQL.ppt
 
Les06
Les06Les06
Les06
 
Restricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data BaseRestricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data Base
 
SQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdfSQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdf
 
Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03
 
Basic SQL Statments
Basic SQL StatmentsBasic SQL Statments
Basic SQL Statments
 
e computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statementse computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statements
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
Module03
Module03Module03
Module03
 

Mehr von Vijay Kumar (14)

Les20
Les20Les20
Les20
 
Les19
Les19Les19
Les19
 
Les17
Les17Les17
Les17
 
Les16
Les16Les16
Les16
 
Les14
Les14Les14
Les14
 
Les13
Les13Les13
Les13
 
Les12
Les12Les12
Les12
 
Les10
Les10Les10
Les10
 
Les11
Les11Les11
Les11
 
Les07
Les07Les07
Les07
 
Les09
Les09Les09
Les09
 
Les08
Les08Les08
Les08
 
Les05
Les05Les05
Les05
 
Les03
Les03Les03
Les03
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Les02

  • 2.
  • 3. Limiting Rows Using a Selection “ retrieve all employees in department 90” EMPLOYEES …
  • 4.
  • 5. Using the WHERE Clause SELECT employee_id, last_name, job_id, department_id FROM employees WHERE department_id = 90 ;
  • 6.
  • 7. Comparison Conditions Operator = > >= < <= <> Meaning Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to
  • 8. Using Comparison Conditions SELECT last_name, salary FROM employees WHERE salary <= 3000;
  • 9. Other Comparison Conditions Operator BETWEEN ...AND... IN(set) LIKE IS NULL Meaning Between two values (inclusive), Match any of a list of values Match a character pattern Is a null value
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Logical Conditions Operator AND OR NOT Meaning Returns TRUE if both component conditions are true Returns TRUE if either component condition is true Returns TRUE if the following condition is false
  • 16. Using the AND Operator AND requires both conditions to be true. SELECT employee_id, last_name, job_id, salary FROM employees WHERE salary >=10000 AND job_id LIKE '%MAN%';
  • 17.
  • 18. Using the NOT Operator SELECT last_name, job_id FROM employees WHERE job_id NOT IN ('IT_PROG', 'ST_CLERK', 'SA_REP');
  • 19. Rules of Precedence Override rules of precedence by using parentheses. Order Evaluated Operator 1 Arithmetic operators 2 Concatenation operator 3 Comparison conditions 4 IS [NOT] NULL , LIKE , [NOT] IN 5 [NOT] BETWEEN 6 NOT logical condition 7 AND logical condition 8 OR logical condition
  • 20. Rules of Precedence SELECT last_name, job_id, salary FROM employees WHERE job_id = 'SA_REP' OR job_id = 'AD_PRES' AND salary > 15000;
  • 21. Rules of Precedence SELECT last_name, job_id, salary FROM employees WHERE (job_id = 'SA_REP' OR job_id = 'AD_PRES') AND salary > 15000; Use parentheses to force priority.
  • 22.
  • 23. Sorting in Descending Order SELECT last_name, job_id, department_id, hire_date FROM employees ORDER BY hire_date DESC ; …
  • 24. Sorting by Column Alias SELECT employee_id, last_name, salary*12 annsal FROM employees ORDER BY annsal; …
  • 25.
  • 26.
  • 27.

Hinweis der Redaktion

  1. Schedule: Timing Topic 45 minutes Lecture 30 minutes Practice 75 minutes Total