21 AND name LIKE '%John%'."> Usage of and in sql-SQL-php.cn
Home> Database> SQL> body text

Usage of and in sql

下次还敢
Release: 2024-05-08 11:18:18
Original
820 people have browsed it

The AND operator is used to combine multiple conditions and returns TRUE only if all conditions are TRUE. Syntax: WHERE condition1 AND condition2 AND ..., where condition is the condition that evaluates to TRUE or FALSE. For example, to get customers whose age is greater than 21 and whose name contains "John", the query is: SELECT * FROM customers WHERE age > 21 AND name LIKE '%John%'.

Usage of and in sql

Usage of AND operator in SQL

AND operator is a logic used to combine multiple conditions in SQL operator. It returns TRUE if and only if all specified conditions are TRUE.

Grammar:

WHERE condition1 AND condition2 AND ...
Copy after login

Among them:

  • condition1,condition2, etc. are evaluations A condition that is TRUE or FALSE.

Usage example:

Consider the following table structure:

CREATE TABLE customers ( id INT PRIMARY KEY, name VARCHAR(255), age INT );
Copy after login

The following query obtains all those whose age is greater than 21 and whose name contains "John" Customer:

SELECT * FROM customers WHERE age > 21 AND name LIKE '%John%';
Copy after login

In this query:

  • age > 21The condition checks if the age of the customer is greater than 21.
  • name LIKE '%John%'The condition checks whether the customer's name contains the substring "John".
  • The AND operator combines these two conditions, ensuring that only customers who meet both conditions are returned.

Note:

  • The AND operator has a higher priority than the OR operator.
  • Brackets can be used to group conditions and control the precedence of operators.
  • The AND operator is different from the && operator, which is used for logical evaluation in programming languages such as Python.

The above is the detailed content of Usage of and in sql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!