Home > Daily Programming > Mysql Knowledge > The rules of and, or and as in mysql

The rules of and, or and as in mysql

下次还敢
Release: 2024-04-27 07:45:38
Original
1003 people have browsed it

The rules of AND, OR and AS in MySQL: AND: true when all conditions are true, and the priority is higher than OR; OR: true when one condition is true, and the priority is lower than AND; AS: for selection The column designation alias is followed by the column alias.

The rules of and, or and as in mysql

Rules for AND, OR and AS in MySQL

AND

  • Combining two or more conditions together, the entire expression is true only when all conditions are true.
  • The AND operator has higher precedence than the OR operator.
  • Grammar: condition1 AND condition2

OR

  • Combine two or more conditions Together, as long as one of the conditions is true, the entire expression is true.
  • The OR operator has lower precedence than the AND operator.
  • Syntax: condition1 OR condition2

AS

  • Specifies the columns selected from the query Alias.
  • AS keyword followed by column alias.
  • Syntax: SELECT column_name AS column_alias

Rules

  • AND and OR operators can be combined use.
  • AS aliases can be used with the AND and OR operators.
  • Brackets can be used to control the precedence of operators.
  • For example:

    <code>SELECT * FROM table_name
    WHERE (column1 = value1 OR column2 = value2)
    AND column3 = value3
    AS result_alias;</code>
    Copy after login

    In this query:

  • ##OR The operator combines column1 and The conditions of column2 are combined together. The
  • AND operator combines the conditions of the OR operator with the conditions of column3. The
  • AS keyword specifies an alias for the query result as result_alias.

The above is the detailed content of The rules of and, or and as in mysql. 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 Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template