forked from ttodua/useful-php-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMYSQL-operators
46 lines (25 loc) · 1.48 KB
/
MYSQL-operators
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
========== COMPARING ====
!=, ^=, <> means "NOT EQUAL": SELECT ENAME FROM EMP WHERE SAL ^= 5000;
>= means "Greater than"......
<= means "lower than"......
========== "LIKE" operator=====================
select all customers, whose City name:
a) starts with letter "z" or "k": SELECT * FROM my_table WHERE City LIKE 'z%' OR City LIKE 'k%';
b) ends with letter "z": SELECT * FROM my_table WHERE City LIKE '%z';
c) contains the word "forni": SELECT * FROM my_table WHERE City LIKE '%forni%';
=========="ANY(some)" operator (Compares a value to each value in a list or returned by a query.) ==================
SELECT * FROM DEPT WHERE LOCATION = SOME ('NEW YORK','DALLAS','CHICAGO' );
[Must be preceded by =, !=, >, <, <=, or >=. Evaluates to FALSE if the query returns no rows. ]
=========="ALL" operator (Compares a value with every value in a list or returned by a query.) ==================
SELECT * FROM emp WHERE myfunds >= ALL (1400, 3000);
[Must be preceded by =, !=, >, <, <=, or >=. Evaluates to TRUE if the query returns no rows. ]
========== "UNION" operator (Returns all distinct rows selected by both query.)
SELECT * FROM
(SELECT ENAME FROM EMP WHERE JOB = 'CLERK'
UNION
SELECT ENAME FROM EMP WHERE JOB = 'ANALYST');
========== "MINUS" operator (Returns all distinct rows selected by the first query but not the second. ) =====================
SELECT * FROM
(SELECT SAL FROM EMP WHERE JOB = 'PRESIDENT'
MINUS
SELECT SAL FROM EMP WHERE JOB = 'MANAGER');