0% found this document useful (0 votes)
51 views

Operators in The WHERE Clause: SELECT DISTINCT City FROM Customers

This document provides examples of using different SQL clauses and operators to select, filter, and manipulate data in databases. Some key examples include using the SELECT statement to retrieve specific columns or rows, the DISTINCT operator to get unique city names, the WHERE clause to filter by country or apply conditional operators like =, <, >, BETWEEN, and IN. It also shows using ORDER BY to sort results and examples of INSERT, UPDATE, DELETE statements to modify database tables.

Uploaded by

Hoai Duc
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Operators in The WHERE Clause: SELECT DISTINCT City FROM Customers

This document provides examples of using different SQL clauses and operators to select, filter, and manipulate data in databases. Some key examples include using the SELECT statement to retrieve specific columns or rows, the DISTINCT operator to get unique city names, the WHERE clause to filter by country or apply conditional operators like =, <, >, BETWEEN, and IN. It also shows using ORDER BY to sort results and examples of INSERT, UPDATE, DELETE statements to modify database tables.

Uploaded by

Hoai Duc
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ly ht bng Example SELECT * FROM Customers; Ly 1 ct city & customers Example SELECT CustomerName,City FROM Customers; Ly 1 ct city

SELECT DISTINCT City FROM Customers; Lc nhng quc gia Mexico SELECT * FROM Customers WHERE Country='Mexico';

Operators in The WHE E !lause


The "ollo#ing operators can be use$ in the WHE E clause% Operator & () ) ( )& (& 2ETWEE* L,3E ,* Description E'ual *ot e'ual+ Note: ,n some -ersions o" ./L this operator may be #ritten as 0& 1reater than Less than 1reater than or e'ual Less than or e'ual 2et#een an inclusi-e range .earch "or a pattern To speci"y multiple possible -alues "or a column

ND! SELECT * FROM Customers WHERE Country='"erm#ny' ND City='$er%in'; OR!


SELECT * FROM Customers WHERE City='Berlin' OR City='M n!"en';

!ombining 4*5 & O


SELECT * FROM Customers WHERE Country='#ermany' $N% &City='Berlin' OR City='M n!"en'';

L&n' s() x*) !


SELECT * FROM Customers OR%ER B( Country; SELECT * FROM Customers OR%ER B( Country %ESC; ELECT * FROM Customers OR%ER B( Country,CustomerName; Chn mt dng trong database )NSERT )NTO Customers &CustomerName, Conta!tName, $**ress, City, +ostalCo*e, Country' ,$L-ES &'Car*inal','Tom B. Eri!"sen','S/a0en 12','Sta3an0er','4556','Nor7ay''; C"8n 2 s9 :";n t< tron0 m=t *>n0 ?@n0 )NSERT )NTO Customers &CustomerName, City, Country' ,$L-ES &'Car*inal', 'Sta3an0er', 'Nor7ay''; SAL u:*ate B -+%$TE Customers SET Conta!tName='$lCre* S!"mi*t', City='Ham?ur0' WHERE CustomerName='$lCre*s Futter/iste';

The ./L 5ELETE .tatement


DELETE FROM Customers WHERE CustomerName=' !"reds Futter#$ste' nders'& ND Conta%tName='Mar$a

./L SELECT TOP !lause


SELECT TO+ 1 * FROM Customers;

./L .ELE!T TO6 6E !E*T Example


The "ollo#ing ./L statement selects the "irst 789 o" the recor$s "rom the :!ustomers: table%

Example SELECT TO+ D5 +ERCENT * FROM Customers;

./L L,3E Operator Examples


SELECT * FROM Customers WHERE City L)EE 'sF';

SELECT * FROM Customers WHERE Country L)EE 'Flan*F';

./L Wil$car$ !haracters


,n ./L; #il$car$ characters are use$ #ith the ./L L,3E operator+ ./L #il$car$s are use$ to search "or $ata #ithin a table+ With ./L; the #il$car$s are% Wildcard 9 @ BcharlistC Description 8 hay nhi<u => t? 1 =A t? !hDn nhEng $Fng cG chH cIi JKu trong BC

BLcharlistC or B0charlistC

Matches only a character *OT speci"ie$ #ithin the brac=ets

+#,-.! %/c c0c' 12n3 c4 xu5t 'i&n c0c 67 t8 9:u ti;n #,<-

./L IN Operator
SELECT * FROM Customers WHERE City )N &'+aris','Lon*on'';

2ETWEE* Operator Example


SELECT * FROM +ro*u!ts WHERE +ri!e BETWEEN 25 $N% 15;

*OT 2ETWEE* Operator Example


SELECT * FROM +ro*u!ts WHERE +ri!e NOT BETWEEN 25 $N% 15;

2ETWEE* Operator #ith ,* Example


SELECT * FROM +ro*u!ts WHERE &+ri!e BETWEEN 25 $N% 15' $N% NOT Cate0ory)% )N &2,1,G';

2ETWEE* Operator #ith Text Nalue Example


SELECT * FROM +ro*u!ts WHERE +ro*u!tName NOT BETWEEN 'C' $N% 'M';

2ETWEE* Operator #ith 5ate Nalue Example


SELECT * FROM Or*ers WHERE Or*er%ate BETWEEN H5IJ54J2KK6H $N% H5IJ5KJ2KK6H;

You might also like