Home >Database >SQL >How to write like in sql is not equal to

How to write like in sql is not equal to

下次还敢
下次还敢Original
2024-04-29 14:24:11882browse

In SQL, use the NOT LIKE operator to query strings that are not equal to a specific pattern. Syntax: SELECT * FROM table_name WHERE column_name NOT LIKE '%pattern%'; where %pattern% is the pattern to be matched, and % represents the wildcard character.

How to write like in sql is not equal to

How to use LIKE query in SQL is not equal

In SQL, we can use the LIKE operator to Matches strings containing a specific pattern. If we want to query for strings that are not equal to a specific pattern, we can use the NOT LIKE operator.

Syntax:

<code>SELECT * FROM table_name WHERE column_name NOT LIKE '%pattern%';</code>

Among them:

  • ##table_name is the name of the table to be queried.
  • column_name is the column name to match the pattern.
  • %pattern% is the pattern to match, where % represents a wildcard character, matching any number of characters.
For example, we want to query all customers whose names do not contain "John" from the

customers table:

<code>SELECT * FROM customers WHERE name NOT LIKE '%John%';</code>
This query will return all customers whose names do not contain "John" "John's" client.

Note:

    If you want to match an exact string without using wildcard characters, use the equal sign (=) operator.
  • If you want to match a string that does not start with a specific pattern, use NOT LIKE '%pattern'.
  • If you want to match a string that does not end with a specific pattern, use NOT LIKE 'pattern%'.

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

Statement:
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
Previous article:How to use like in sqlNext article:How to use like in sql