Three uses and differences of MySQL not equal

Three uses and differences of MySQL not equal

Judgment symbols are often used in MySQL, and not equal to is a more commonly used symbol . The following three not equal to symbols are explained

symbol significance
<> The earliest use of inequality is more portable than the following two
!= Later, MySQL added a function similar to the not equal to function in programming languages ​​such as Java.
not in Add data after "not in" to indicate that it is not in the data.

MySQL recommends using <> to indicate inequality . Why? Because of its strong portability and fast query speed . There is a question on LeetCode, which is a movie theater query question. The title is as follows:

insert image description here

In fact, it is very simple. You can query descriptions that are not boring and ids that are not even numbers, and sort the query results using order by. However, when querying descriptions that are not boring, you need to use the not equal to judgment. The following is a comparison of the query time I used three not equal to

insert image description here

It can be seen that <> is still faster, so it is recommended to use <> to indicate inequality.

There is no point in saying more, let’s give an example! ! !

A simple table data:

select * from user where address != "北京" 

select * from user where address <> "Beijing"

select * from user where address = null

select * from user where address is null

select * from user where address != null

Summarize:

select * from user where address != "北京"
 
select * from user where address <> "Beijing"
 
select * from user where address = null
select * from user where address is null
 
select * from user where address != null
select * from user where address is not null

Just a few sentences and three extremely common points, perhaps we are at a loss and hesitant when answering.

In <> and! = are equivalent. When a field is not equal to a certain value (a non-empty value), the output result is that this field is empty and not output.

is and is not are used in conjunction with null . I call it is not, not empty.

This concludes this article about the three uses and differences of MySQL not equal. For more relevant MySQL not equal content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of how to write mysql not equal to null and equal to null
  • mysql not equal to symbol writing

<<:  Ten Experiences in Web Design in 2008

>>:  Vue+openlayer5 method to get the coordinates of the current mouse slide

Recommend

MySQL 5.7.18 version free installation configuration tutorial

MySQL is divided into installation version and fr...

Example of viewing and modifying MySQL transaction isolation level

Check the transaction isolation level In MySQL, y...

Detailed explanation of mixins in Vue.js

Mixins provide distributed reusable functionality...

Is it necessary to give alt attribute to img image tag?

Do you add an alt attribute to the img image tag? ...

Simple summary of tomcat performance optimization methods

Tomcat itself optimization Tomcat Memory Optimiza...

Example of how to generate random numbers and concatenate strings in MySQL

This article uses an example to describe how MySQ...

TypeScript learning notes: type narrowing

Table of contents Preface Type Inference Truth va...

How to use Maxwell to synchronize MySQL data in real time

Table of contents About Maxwell Configuration and...

Docker installation and configuration steps for MySQL

Table of contents Preface environment Install Cre...

JavaScript to implement the function of changing avatar

This article shares the specific code of JavaScri...

Vue realizes the sliding cross effect of the ball

This article example shares the specific code of ...

HTML simple shopping quantity applet

This article shares a simple HTML shopping quanti...

JavaScript realizes the drag effect of modal box

Here is a case of modal box dragging. The functio...

Use href in html to pop up a file download dialog box when clicking a link

I learned a new trick today. I didn’t know it befo...