If you have recently performed SELECT or UPDATE queries, you may have used one or more MySQL comparison operators to limit the query output results. Comparison is an integral part of most SELECT queries, and MySQL provides many functions for this function. according to the last statistics, it has more than 20 such operators and functions, from the famous and LIKE, to more, if you have recently performed SELECT or UPDATE queries, you may have used one or more MySQL comparison operators to limit the query output results. Comparison is an integral part of most SELECT queries, and MySQL provides many functions for this function. according to the last statistics, it has more than 20 such operators and functions, from the famous = and LIKE to the more difficult not in and STRCMP (). 1VY4K4 |} S
GM = sL
This article focuses on some less common MySQL data comparison functions and operators, discusses how they can be used to compare strings, numbers, dates, times, or user-supplied values in table fields in an application. 2X {r {C
Jlt0N) 5
BETWEEN? E6 | E. S2
CZ1 % MK (c:
The BETWEEN operator is a useful method to test whether a value or a date value exists in a certain range. This operator accepts two parameters, maximum and minimum, and tests whether the provided values are within the range of these two values. If it is within this range, the operator returns a boolean value -- true; otherwise, it returns a pseudo value. The following is an example: LO {e % I &{;
Vnv4 | ^ ZNnQ
Mysql> SELECT 2350 BETWEEN 100 AND 10000;: k4RPM7oS
+ ---------------------------- + L % T6ai1 ~
| 2350 BETWEEN 100 AND 10000 | 1 H -~ CV1c
+ ---------------------------- + QvmGwFO
| 1 | M # FhJvE4QJ
+ ---------------------------- + M5HY $ 9d
1 row in set (0.18 sec )! VBxXnY;
1z2% TZ ='
The following two examples use the date value YXV 9Mi.
5 "" & 3
Mysql> SELECT 20060405 BETWEEN 20060101 AND 20070101; fUue U | 5
+ ---------------------------------------- +: BSK WoQ {
| 20060405 BETWEEN 20060101 AND 20070101 | MVW] | Lv
+ -------------------------------------- + 9 'ia <~ X4N
| 1 | I | W/(Q @ 9
+ ---------------------------------------- +> Nr? U % "c
1 row in set (0.00 sec) xqTpW.1
^ N [lQh
Mysql> SELECT 20060405 BETWEEN 20060101 AND 20060401; "7 mG + Ak
+ -------------------------------------- + P $ @ ch4i
| 20060405 BETWEEN 20060101 AND 20060401 |-c-[K6a _
+ ---------------------------------------- + 8hM? I _} IQ
| 0 | _ O7sBx &
+ ---------------------------------------- + [) 51f + oC8
1 row in set (0.00 sec )? N1LMD1qp $
7l E & D
GREATEST and LEAST * p @ 1} e} &
$ (J> m: j
The GREATEST and LEAST operators provide a convenient way to determine the maximum and minimum values of a group of numbers or time values. When you look at the names, you will know the functions of these two operators-The following is an example of using the GREATEST operator for a group of dates: + q + cyX
9zw7; jz ^ +
Mysql> select greatest (20000601,200 20000604,); GC) XtG5b
+ ---------------------------------------- + = [| IEZYq
| GREATEST (20000601,200 20000604,) |: Op \ PrM1f
+ -------------------------------------- + | VLQb * Q
| 20000604 | BE ^ "n} 75
+ -------------------------------------- + 5 | GFPd \ Pg
1 row in set (0.00 sec) Xcq4XGwnj
@ M2o A.7
The following is an example of using the LEAST operator for a set of values:] Hm ^ _ f +
OewSeplb
Mysql> select least (100,200, 50,-6,-73,100 0); = PF: Xj!
+ ------------------------------------ + Y/"C aKm
| LEAST (100,200, 50,-6,-73,100 0) | 0Ad =, 0z
+ ------------------------------------ + QVV? [C8K
|-73 | ZKivc xF3L
+ ------------------------------------ + "D KO '1
1 row in set (0.03 sec)
If you have recently performed SELECT or UPDATE queries, you may have used one or more MySQL comparison operators to limit the query output results. Comparison is an integral part of most SELECT queries, and MySQL provides many functions for this function. according to the last statistics, it has more than 20 such operators and functions, from the famous = and LIKE to the more difficult not in and STRCMP (). W <wYS 0/
'[9ieXPB -_
This article focuses on some less common MySQL data comparison functions and operators, discusses how they can be used to compare strings, numbers, dates, times, or user-supplied values in table fields in an application. CH5u; zK4'
Xi2 "w r9
BETWEEN ''iuka
} MmNDq
The BETWEEN operator is a useful method to test whether a value or a date value exists in a certain range. This operator accepts two parameters, maximum and minimum, and tests whether the provided values are within the range of these two values. If it is within this range, the operator returns a boolean value -- true; otherwise, it returns a pseudo value. The following is an example: TC ^ '&"
Nlw6 G_bLF
Mysql> SELECT 2350 BETWEEN 100 AND 10000;): zC9 ;:
+ ---------------------------- + LxyZm
| 2350 BETWEEN 100 AND 10000 | v "6 * y2a N
+ ---------------------------- + \ 91 $ M @
| 1 | V5 +] n
+ ---------------------------- + LSt 1 row in set (0.18 sec); R> | * y
Z | US ~ Tl
The following two examples use the date value * 75TVy? D
] Rrpq % z
Mysql> SELECT 20060405 BETWEEN 20060101 AND 20070101; NC> E (z
+ ---------------------------------------- + 5 + BUJB4_pM
| 20060405 BETWEEN 20060101 AND 20070101 | d1 ^ 1 cr
+ -------------------------------------- + ID] | sX % ^ 0
| 1 | 3 + = E {_ 0C
+ ---------------------------------------- +} TDp ('^
1 row in set (0.00 sec) F {ewZsjd =
NVXTQ & | Xx
Mysql> SELECT 20060405 BETWEEN 20060101 AND 20060401; {. '+ W
+ ---------------------------------------- +]} O0 nriE
| 20060405 BETWEEN 20060101 AND 20060401 | EXRP \ Fh
+ ---------------------------------------- + PznE <
| 0 |. 6 & l' O /#
+ -------------------------------------- + Iv. i5Y5
1 row in set (0.00 sec) Q % 2 WeRU //
3_HF8
GREATEST and LEAST e !} S7 * RyN-
($. ZdoUr & v
The GREATEST and LEAST operators provide a convenient way to determine the maximum and minimum values of a group of numbers or time values. When you look at the names, you will know the functions of these two operators. The following is an example of using the GREATEST operator for a group of dates:> oh! Wq [+
'G ~ OfP8
Mysql> select greatest (20000601,200 20000604,); F6 $ l {bm
+ -------------------------------------- + H * 1o5vg
| GREATEST (20000601,200 20000604,) |} YXH: 8I
+ ---------------------------------------- +. 62Dx {
| 20000604 | t! % I/: j '[
+ -------------------------------------- + U) 12rx
1 row in set (0.00 sec) h, NJ. mK
MFVN %. E r
The following is an example of using the LEAST operator for a set of values: Q, rcyIM
O1S4 #? Sy
Mysql> select least (100,200, 50,-6,-73,100 0); S 9) TvQ
+ ------------------------------------ + 5Nhr | @ b0
| LEAST (100,200, 50,-6,-73,100 0) | SNi9WIjP'
+ ------------------------------------ + RIo qO #3
|-73 | #: z &) Y & C
+ ------------------------------------ +) % 8e1rB
1 row in set (0.03 sec)