Introduction to MySQL <> and <=> operators

Introduction to MySQL <> and <=> operators

<> Operator

Function: Indicates not equal to.

Note: It has the same function as the “!=” operator, but “<>” is less readable.

### To query non-Han users, the following two statements have the same effect.
> SELECT * FROM user WHERE nation != "汉族";
> SELECT * FROM user WHERE nation <> "Han";

<=> Operator

Function: Safety is equal to

Note: It integrates the functions of the "=" operator and the IS keyword, and can determine both NULL and basic data types. But in comparison, “<=>” is less readable.

From the following SQL statement, we can see that the "=" operator and the IS keyword cannot be used interchangeably. The "=" operator can only determine basic data types, and the IS keyword can only determine NULL.

The "<=>" operator can be used in relatively few scenarios. It can basically only be used for search conditions. There is no need to determine whether a search condition is NULL or a basic data type.

### Query users who have not filled in their gender. The following statements have the same effect> SELECT * FROM user WHERE sex IS NULL;
> SELECT * FROM user WHERE sex <=> NULL;
 
### Query male users. The following statements have the same effect> SELECT * FROM user WHERE sex = "男";
> SELECT * FROM user WHERE sex <=> "male";

This is the end of this article about the MySQL <> and <=> operators. For more related MySQL <> and <=> content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MYSQL Operator Summary
  • Detailed explanation of the use of MySQL comparison operator regular expression matching REGEXP
  • Summary of the use of special operators in MySql
  • Summary of commonly used operators and functions in MySQL
  • MySQL Notes — SQL Operators

<<:  HTML table markup tutorial (1): Creating a table

>>:  vue+el-upload realizes dynamic upload of multiple files

Recommend

Brief analysis of mysql scheduled backup tasks

Introduction In a production environment, in orde...

npm Taobao mirror modification explanation

1. Top-level usage 1. Install cnpm npm i -g cnpm ...

6 inheritance methods of JS advanced ES6

Table of contents 1. Prototype chain inheritance ...

Example of how to implement local fuzzy search function in front-end JavaScript

Table of contents 1. Project Prospects 2. Knowled...

Docker data volume common operation code examples

If the developer uses Dockerfile to build the ima...

Design reference WordPress website building success case

Each of these 16 sites is worth reading carefully,...

52 SQL statements to teach you performance optimization

1. To optimize the query, try to avoid full table...

MySQL subqueries and grouped queries

Table of contents Overview Subqueries Subquery Cl...

JavaScript to achieve lottery effect

This article shares the specific code of JavaScri...

How to use mysqladmin to get the current TPS and QPS of a MySQL instance

mysqladmin is an official mysql client program th...

What are Web Slices?

IE8 new feature Web Slices (Web Slices) Microsoft...

The webpage cannot be opened because the div element lacks a closing tag

At first I thought it was a speed issue, so I late...