Home Database Mysql Tutorial What are the comparison operators?

What are the comparison operators?

Jul 12, 2021 pm 02:46 PM
comparison operator

Comparison operators include: =, "", " (!=)", "=", >, "IS NULL ”, “IS NOT NULL”, LEAST, GREATEST, IN, “”NOT IN”, LIKE, REGEXP, etc.

What are the comparison operators?

this Tutorial operating environment: windows7 system, mysql8 version, Dell G3 computer.

Comparison operators can be used to compare numbers and strings. Today I will post a detailed explanation of Mysql comparison operators, I hope it will be helpful to beginners, although NoSQL is popular now, but MYSQL is still very useful. Numbers are compared as floating point values, strings are compared with differences as an example, and the = operator is used to compare whether both sides of an expression are equal. You can also compare strings.

Operators are used to test whether both sides of an expression are not equal and return a true value if they are not equal.

You can also compare strings.

Comparison operators

The result of a comparison operator is always 1, 0 or NULL. The comparison operators in MySQL are:

=, , (!=) , =, >, IS NULL, IS NOT NULL, LEAST, GREATEST, BETWEEN . . . AND. . . , ISNULL, IN, NOT IN, LIKE, REGEXP

Use' =' To judge equality, the SQL statement is as follows:

SELECT 1=0, '2'=2, 2=2,'0.02'=0, 'b'='b', (1+3) = (2+2),NULL=NULL;
Copy after login

What are the comparison operators?

Use '<=>' to judge equality, the SQL statement is as follows:

What are the comparison operators?

As you can see from the results, '<=>' has a similar effect to '=' when performing comparison operations. The only difference is that '<=>' can be used Judge NULL, and the return value is 1 when both are NULL.

Not equal to operator<> or !=

'<>'or'!=' Used to judge whether numbers, strings, or expressions are not equal. If they are not equal, the return value is 1; otherwise, the return value is 0. These two operators cannot be used to judge the empty value NULL.

Use '<>' and '!=' are used to judge inequality. The SQL statement is as follows:

SELECT &#39;good&#39;<>&#39;god&#39;, 1<>2, 4!=4, 5.5!=5, (1+3)!=(2+1),NULL<>NULL;
Copy after login

What are the comparison operators?

It can be seen from the results that the two inequality operators work Same, you can compare numbers, strings, and expressions.

Use '<=' for comparison and judgment. The SQL statement is as follows:

SELECT &#39;good&#39;<=&#39;god&#39;, 1<=2, 4<=4, 5.5<=5, (1+3) <= (2+1),NULL<=NULL;
Copy after login

What are the comparison operators?

As you can see from the results, when the left operand is less than or equal to the right, the return value is 1, for example: 4<=4; when the left operand is greater than the right, the return value is 0, for example: 'good' 3rd The 'o' character at position is greater in the alphabet than the 'd' character at position 3 in 'god', so the return value is 0; NULL is also returned when comparing NULL values.

Use '<' for comparison and judgment, the SQL statement is as follows:

SELECT &#39;good&#39;<&#39;god&#39;, 1<2, 4<4, 5.5<5, (1+3) < (2+1),NULL<NULL;
Copy after login

What are the comparison operators?

Use '>=' for comparison and judgment, the SQL statement is as follows:

SELECT &#39;good&#39;>=&#39;god&#39;, 1>=2, 4>=4, 5.5>=5, (1+3) >= (2+1),NULL>=NULL;
Copy after login

What are the comparison operators?

Use '>' for comparison and judgment. The SQL statement is as follows:

SELECT &#39;good&#39;>&#39;god&#39;, 1>2, 4>4, 5.5>5, (1+3) > (2+1),NULL>NULL;
Copy after login

What are the comparison operators?

Use IS NULL, ISNULL and IS NOT NULL determines NULL values ​​and non-NULL values. The SQL statement is as follows:

SELECT NULL IS NULL, ISNULL(NULL),ISNULL(10), 10 IS NOT NULL;
Copy after login

What are the comparison operators?

Use BETWEEN AND to judge the value range. Enter the SQL statement as follows:

SELECT 4 BETWEEN 4 AND 6, 4 BETWEEN 4 AND 6,12 BETWEEN 9 AND 10;
Copy after login

What are the comparison operators?

SELECT &#39;x&#39; BETWEEN &#39;f&#39; AND &#39;g&#39;, &#39;b&#39; BETWEEN &#39;a&#39; AND &#39;c&#39;;
Copy after login

What are the comparison operators?

Use the LEAST operator to determine the size. The SQL statement is as follows:

SELECT least(2,0), least(20.0,3.0,100.5), least(&#39;a&#39;,&#39;c&#39;,&#39;b&#39;),least(10,NULL);
Copy after login

What are the comparison operators?

使用GREATEST运算符进行大小判断,SQL语句如下:

SELECT greatest(2,0), greatest(20.0,3.0,100.5), greatest(&#39;a&#39;,&#39;c&#39;,&#39;b&#39;),greatest(10,NULL);
Copy after login

What are the comparison operators?

使用IN、NOT IN运算符进行判断,SQL语句如下:

SELECT 2 IN (1,3,5,&#39;thks&#39;), &#39;thks&#39; IN (1,3,5,&#39;thks&#39;);
Copy after login

What are the comparison operators?

存在NULL值时的IN查询,SQL语句如下:

SELECT NULL IN (1,3,5,&#39;thks&#39;),10 IN (1,3,NULL,&#39;thks&#39;);
Copy after login

What are the comparison operators?

使用运算符LIKE进行字符串匹配运算,SQL语句如下:

SELECT &#39;stud&#39; LIKE &#39;stud&#39;, &#39;stud&#39; LIKE &#39;stu_&#39;,&#39;stud&#39; LIKE &#39;%d&#39;,&#39;stud&#39; LIKE &#39;t_ _ _&#39;, &#39;s&#39; LIKE NULL;
Copy after login

What are the comparison operators?

使用运算符REGEXP进行字符串匹配运算,SQL语句如下:

SELECT &#39;ssky&#39; REGEXP &#39;^s&#39;, &#39;ssky&#39; REGEXP &#39;y$&#39;, &#39;ssky&#39; REGEXP &#39;.sky&#39;, &#39;ssky&#39; REGEXP &#39;[ab]&#39;;
Copy after login

What are the comparison operators?

扩展资料:

逻辑运算符

逻辑运算符的求值所得结果均为TRUE、FALSE或NULL。

逻辑运算符有:

  • NOT 或者 !

  • AND 或者 &&

  • OR 或者 ||

  • XOR(异或)

使用非运算符“NOT”和“!”进行逻辑判断,SQL语句如下:

SELECT NOT 10, NOT (1-1), NOT -5, NOT NULL, NOT 1 + 1;
Copy after login

What are the comparison operators?

SELECT !10, !(1-1), !-5, ! NULL, ! 1 + 1;
Copy after login

What are the comparison operators?

使用与运算符“AND”和“&&”进行逻辑判断,SQL语句如下:

SELECT 1 AND -1,1 AND 0,1 AND NULL, 0 AND NULL;
Copy after login

What are the comparison operators?

SELECT 1 && -1,1 && 0,1 && NULL, 0 && NULL;
Copy after login

What are the comparison operators?

使用或运算符“OR”和“||”进行逻辑判断,SQL语句如下:

SELECT 1 OR -1 OR 0, 1 OR 2,1 OR NULL, 0 OR NULL, NULL OR NULL;
Copy after login

What are the comparison operators?

SELECT 1 || -1 || 0, 1 || 2,1 || NULL, 0 || NULL, NULL || NULL;
Copy after login

What are the comparison operators?

使用异或运算符“XOR”进行逻辑判断,SQL语句如下:

SELECT 1 XOR 1, 0 XOR 0, 1 XOR 0, 1 XOR NULL, 1 XOR 1 XOR 1;
Copy after login

执行上面的语句,结果如下。

What are the comparison operators?

位运算符

位运算符是用来对二进制字节中的位进行测试、移位或者测试处理。位运算符有:

  • 位或(|)

  • 位与(&)

  • 位异或(^ )

  • 位左移(<<)

  • 位右移(<<)

  • 位取反(~)

使用位或运算符进行运算,SQL语句如下:

SELECT 10 | 15, 9 | 4 | 2;
Copy after login

What are the comparison operators?

使用位与运算符进行运算,SQL语句如下:

SELECT 10 & 15, 9 &4& 2;
Copy after login

What are the comparison operators?

使用位异或运算符进行运算,SQL语句如下:

SELECT 10 ^ 15, 1 ^0, 1 ^ 1;
Copy after login

What are the comparison operators?

使用位左移运算符进行运算,SQL语句如下:

SELECT 1<<2, 4<<2;
Copy after login

What are the comparison operators?

使用位右移运算符进行运算,SQL语句如下:

SELECT 1>>1, 16>>2;
Copy after login

What are the comparison operators?

使用位取反运算符进行运算,SQL语句如下:

SELECT 5 & ~1;
Copy after login

What are the comparison operators?


运算符的优先级

  • 运算的优先级决定了不同的运算符在表达式中计算的先后顺序。

  • 级别高的运算符先进行计算,如果级别相同,MySQL按表达式的顺序从左到右依次计算。当然,在无法确定优先级的情况下,可以使用圆括号“()”来改变优先级。

默认情况下,MySQL相关论文,对不区是区分大小写的。如果你需要区分,你需要添加二进制关键字。

=,运算符用于比较表达式的左侧是否小于或等于、大于或等于、小于或大于右侧。

between运算符用于检测某个值是否存在于指定范围内。其中它返回真实值。

您可以添加一个非逻辑运算符来否定between比较,只有当表达式在给定范围之外时,才会返回真值。

in运算符用于验证一个值是否包含在一组指定的值中。其中返回真实值。

为空和非空运算符用于执行包含空值的比较操作

运算符称为空安全等号

相似运算符的通配符。

当使用包含like运算符的查询时,建议确保对where子句中命中的列进行索引,并且where子句包含足够的数据来限制开头搜索的记录数。

相关推荐:《mysql教程

The above is the detailed content of What are the comparison operators?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the meaning of '==' symbol in php What is the meaning of '==' symbol in php Mar 14, 2023 pm 07:05 PM

In PHP, the "==" symbol is a comparison operator that can compare whether two operands are equal. The syntax is "operand 1 == operand 2". The "==" operator compares and tests whether the variable on the left (expression or constant) has the same value as the variable on the right (expression or constant); it only compares the values ​​of the variables, not the data types. If the two values ​​are the same, it returns a true value; if the two values ​​are not the same, it returns a false value.

Python Operators: The Ultimate Guide from Newbie to Master Python Operators: The Ultimate Guide from Newbie to Master Mar 11, 2024 am 09:13 AM

Introduction to python operators Operators are special symbols or keywords used to perform operations between two or more operands. Python provides a variety of operators covering a wide range of uses, from basic mathematical operations to complex data manipulation. Mathematical operators Mathematical operators are used to perform common mathematical operations. They include: operator operation examples + addition a + b - subtraction a-b * multiplication a * b / division a / b % modulo operation (take the remainder) a % b ** power operation a ** b // integer division (discard the remainder) a//b Logical Operators Logical operators are used to concatenate Boolean values ​​and evaluate conditions. They include: operator operations examples and logical and aandbor logical or aorbnot logical not nota comparison operations

The Secret Garden of Operators: Discover Hidden Treasures in Python The Secret Garden of Operators: Discover Hidden Treasures in Python Mar 11, 2024 am 09:13 AM

The Secret Garden of Operators Python operators are symbols or keywords used to perform various operations. They enable developers to express complex logic concisely and clearly and improve code efficiency. Python provides a wide range of operator types, each with its specific purpose and usage. Logical Operators Logical operators are used to combine Boolean values ​​and perform logical operations. The main ones are: and: Returns the Boolean value True, if all operands are True, otherwise it returns False. or: Returns a Boolean value True if any operand is True, otherwise returns False. not: Negate the Boolean value, change True to False, and change False to True. Demo code: x=Truey

Uncovering the Power of Python Operators: Writing Elegant and Efficient Code Uncovering the Power of Python Operators: Writing Elegant and Efficient Code Mar 11, 2024 am 09:28 AM

Python operators are a key component of the programming language, enabling developers to perform a wide range of operations, from simple arithmetic to complex bit manipulation. Mastering the syntax, semantics, and functionality of operators is essential to using Python effectively. Arithmetic Operators Arithmetic operators are used to perform basic arithmetic operations. They include addition (+), subtraction (-), multiplication (*), division (/), modulo (%), exponentiation (**), and floor division (//). The following example demonstrates the use of arithmetic operators: >>a=10>>b=5#Addition c=a+bprint(c)#Output: 15#Subtraction c=a-bprint(c)#Output: 5#Multiplication c=a*bprint(c)#output

PHP equality comparison: a deeper understanding of how the == operator works PHP equality comparison: a deeper understanding of how the == operator works Apr 09, 2024 pm 03:18 PM

Equality comparison in PHP involves the == operator. It has two types: strict comparison (===) and non-strict comparison (==). The latter can produce unexpected results because variables of different types can be converted to the same type and then compared. To ensure that values ​​are equal and of the same type, use strict comparison.

What do three equal signs mean in php What do three equal signs mean in php Jan 10, 2023 am 10:53 AM

In PHP, the three equal signs "===" are congruent comparison operators, used to compare whether the values ​​of two operands are equal; this operator performs a strict comparison between given variables or values ​​and will compare and see if two variables (expressions or constants) are equal in value and have the same data type, i.e. both are strings or both are integers and so on. This operator returns true if two variables (expressions or constants) contain the same value and the same data type, otherwise it returns false.

Secrets of Python Operators: Mastering the Cornerstone of Programming Secrets of Python Operators: Mastering the Cornerstone of Programming Mar 11, 2024 am 09:19 AM

Python operators are special symbols or words used to perform specific operations on values ​​or to combine values. They are the fundamental building blocks of programming languages ​​and are key to understanding and writing efficient code. Arithmetic Operators Arithmetic operators are used to perform basic mathematical operations such as addition, subtraction, multiplication, division, and remainder. The following are the most commonly used arithmetic operators: +Addition-Subtraction*Multiplication/Division%Remainder Example: x=10y=5print(x+y)#Output: 15print(x-y)#Output: 5print(x*y)#Output :50print(x/y)#Output: 2.0print(x%y)#Output: 0 Comparison Operator The comparison operator is used to compare two values ​​and return a Boolean value (True

How to do type comparison in PHP How to do type comparison in PHP Mar 22, 2023 am 09:29 AM

PHP is a popular server-side scripting language commonly used to develop dynamic websites and web applications. A common task is to compare values ​​of different types. In PHP, you can compare int, float, string, and other types of values ​​using a series of comparison operators. This article will introduce how to perform type comparison in PHP.

See all articles