Home  >  Article  >  Database  >  How to use not equal in mysql

How to use not equal in mysql

PHPz
PHPzforward
2023-05-29 18:07:132319browse

Is not equal in mysql

Is not equal in mysql, , !=, is not It is useless to say more, let’s give an example! ! !

A simple surface data:

How to use not equal in mysql

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

How to use not equal in mysql

select * from user where address <> "北京"

How to use not equal in mysql

select * from user where address = null

How to use not equal in mysql

select * from user where address is null

How to use not equal in mysql

select * from user where address != null

How to use not equal in mysql

Summary:

select * from user where address != "北京"
 
select * from user where address <> "北京"
 
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, three extremely common points , perhaps we are at a loss when answering, hesitant.

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

is and is not are used to combine with null, I call it not, not empty

Additional: MySQL query: not equal to Usage method (mysql query is not equal to)

The popular relational database system MySQL provides a set of SQL query statements for obtaining relevant information from the database. Usually, users use SQL to find specific items. In order to get useful results, we need to use comparison operators. If we find something that is not equal to a specific parameter from the database, we can use the "not equal to" operator () operation.

The "not equal to" operator can be used to compare string and numeric values ​​in MySQL. It can be used in the SELECT.. FROM statement and WHERE clause.

The following is an example to demonstrate how to use the inequality operator:

Suppose there is a table called student, a field is name, and there are several rows of records in it..

| name |

|———–|

| John |

| Tom |

| Alex |

| Mark |

To find the records whose name is not equal to Tom from these records, we can use such a query after the where statement:

SELECT * FROM student
WHERE name ‘Tom&#39;;

Run the above query, the result table shows:

| name |

##|———–|

| John |

| Alex |

| Mark |

Finally, it is worth noting that there is also an inequality operator called "!=" in MySQL. The usage is exactly the same as "", so you can use them interchangeably at any time, for example:

SELECT * FROM student
WHERE name != ‘Tom&#39;;

The result is also:

| name |

| ———–|

| John |

| Alex |

| Mark |

The above is the detailed content of How to use not equal in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete