zoukankan      html  css  js  c++  java
  • A2-02-04.DML-MySQL AND Operator

    转载自:http://www.mysqltutorial.org/mysql-and/

    MySQL AND Operator

     

    Summary: in this tutorial, you will learn how to the MySQL AND operator to combine multiple Boolean expressions to filter data.

    Introduction to MySQL AND operator

    The AND operator is a logical operator that combines two or more Boolean expressions and returns true only if both expressions evaluate to true. The AND operator returns false if one of the two expressions evaluate to false.

    The following illustrates the results of the AND operator when combining true, false, and null.

     TRUEFALSENULL
    TRUE TRUE FALSE NULL
    FALSE FALSE FALSE FALSE
    NULL NULL FALSE NULL

    The AND operator is often used in the WHERE clause of the SELECTUPDATEDELETE statement to form Boolean expressions. The AND operator is also used in join conditions of the  INNER JOIN and  LEFT JOIN clauses.

    When evaluating an expression that has the AND operator, MySQL evaluates the remaining parts of the expression until it can determine the result. This function is called short-circuit evaluation.

    Consider the following example.

    Try It Out

    Note that in MySQL, zero is considered as false and non-zero is treated as true.

    MySQL only evaluates the first part 1 = 0 of the expression 1 = 0 AND 1  / 0. Because the expression 1 = 0 returns false, MySQL can conclude the result of the whole expression, which is false. MySQL then does not evaluate the remaining part of the expression, which is 1/0; If it does, it will issue an error because of the division by zero error.

    MySQL AND operator examples

    Let’s use the customers table in the sample database for the demonstration.

    Customers Table

    The following statement retrieve customers who locate in California (CA) and USA. It uses the ANDoperator in the expression of the WHERE clause.

    Try It Out

    MySQL AND operator example

    With the AND operator, you can combine more than two Boolean expressions. For example, the following query returns the customers who locate in California, USA, and has credit limit greater than 100K.

    Try It Out

    MySQL AND operator more than two expressions

    In this tutorial, we have shown you how to use the MySQL AND operator to combine two or more expressions to form a complex predicate for the WHERE clause.

  • 相关阅读:
    Git SVN 版本控制 简介 总结 MD
    shape selector 背景 圆形 矩形 圆环 [MD]
    eclipse library jar包 使用总结 MD
    Visitor 访问者模式 [MD]
    BlazeMeter+Jmeter 搭建接口测试框架
    nGrinder 简易使用教程
    65个面试常见问题技巧回答(绝对实用)
    [面试技巧]16个经典面试问题回答思路
    质量模型测试电梯
    linux apache服务器优化建议整理(很实用)
  • 原文地址:https://www.cnblogs.com/zhuntidaoren/p/9511507.html
Copyright © 2011-2022 走看看