Gegevens beperken

Introductie tot Oracle SQL

Sara Billen

Curriculum Manager

Rijen filteren

Filter

 

  • Vergelijkingsoperatoren
  • Vergelijkingssleutelwoorden
  • Logische operatoren
Introductie tot Oracle SQL

WHERE

SELECT FirstName, LastName, Country 
FROM Customer
WHERE Country = 'Portugal'
| FirstName | LastName  | Country  |
|-----------|-----------|----------|
| João      | Fernandes | Portugal |
| Madalena  | Sampaio   | Portugal |
Introductie tot Oracle SQL

Vergelijkingsoperatoren

Operator Beschrijving
> Groter dan
>= Groter dan of gelijk aan
< Kleiner dan
<= Kleiner dan of gelijk aan
= Gelijk aan
<> Niet gelijk aan
SELECT UnitPrice
FROM Track
WHERE UnitPrice <> 0.99
Introductie tot Oracle SQL

Vergelijkingssleutelwoorden

  Extra features voor de WHERE-clausule

Introductie tot Oracle SQL

Vergelijkingssleutelwoorden - BETWEEN

SELECT Name, Milliseconds 
FROM Track
WHERE Milliseconds BETWEEN 100000 AND 200000
| Name              | Milliseconds |
|-------------------|--------------|
| Perfect           | 188133       |
| Right Through You | 176117       |
| We Die Young      | 152084       |
| Put You Down      | 196231       |
| ...                              |
Introductie tot Oracle SQL

Vergelijkingssleutelwoorden - IN

SELECT EmployeeId, LastName, Title
FROM Employee
WHERE EmployeeId IN (4, 5, 6)
| EmployeeId | LastName | Title               |
|------------|----------|---------------------|
| 4          | Park     | Sales Support Agent |
| 5          | Johnson  | Sales Support Agent |
| 6          | Mitchell | IT Manager          |
Introductie tot Oracle SQL

Vergelijkingssleutelwoorden - LIKE

Selecteer rijen die op een tekenpatroon passen met LIKE

 

Symbool Beschrijving
% Staat voor elke reeks van 0 of meer tekens
_ Staat voor precies één teken
Introductie tot Oracle SQL

Vergelijkingssleutelwoorden - LIKE

SELECT LastName
FROM Employee
WHERE LastName LIKE '_a%'
| LastName |
|----------|
| Park     |
| Callahan |
Introductie tot Oracle SQL

Logische operatoren

  Logische operatoren

Introductie tot Oracle SQL

Logische operatoren - AND

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry = 'Australia' 
      AND Total > 4
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 66        | Australia      | 5.94  |
| 250       | Australia      | 13.86 |
| 305       | Australia      | 8.91  |
Introductie tot Oracle SQL

Logische operatoren - OR

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry = 'Australia' 
      OR Total > 4
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 3         | Belgium        | 5.94  |
| 4         | Canada         | 8.91  |
| 5         | USA            | 13.86 |
| 10        | Ireland        | 5.94  |
| ...                                |
Introductie tot Oracle SQL

Logische operatoren - NOT

SELECT InvoiceId, BillingCountry, Total
FROM Invoice
WHERE BillingCountry NOT IN ('Australia', 'Canada', 'United Kingdom')
| InvoiceId | BillingCountry | Total |
|-----------|----------------|-------|
| 1         | Germany        | 1.98  |
| 2         | Norway         | 3.96  |
| 3         | Belgium        | 5.94  |
| 5         | USA            | 13.86 |
| ...                                |
Introductie tot Oracle SQL

Samenvatting

WHERE: filter rijen op basis van een voorwaarde

  • Vergelijkingsoperatoren: =, <, >, <=, >=, <>
  • Vergelijkingssleutelwoorden: BETWEEN, IN, LIKE
  • Logische operatoren: AND, OR, NOT
Introductie tot Oracle SQL

Laten we oefenen!

Introductie tot Oracle SQL

Preparing Video For Download...