本MySQL教程将通过语法和示例说明了如何在MySQL查询中一起使用AND运算符和OR运算符。
当同时使用AND和OR时, 可以使用括号 ()指定运行优先顺序。
MySQL中AND条件和OR条件的语法为:
WHERE
condition1
AND
condition2
...
OR
condition_n;
##MySQL 同时使用AND和OR运算符例子
SELECT
*
FROM
customers
(state =
'California'
last_name =
'Johnson'
)
(customer_id > 30);
在California并且名字为Johnson的客户,和 customer_id大于30的客户都将被放到结果集中。
另外一个例子:
customer_id, last_name, first_name
(last_name =
'Anderson'
state =
'Smith'
status =
'Active'
'Florida'
);
将返回下面这些客户:
INSERT
INTO
suppliers
(SupplierID, ContactName)
CustomerID, ContactName
(ContactName =
'Helen Bennett'
ContactName =
'John Steel'
CustomerID >= 16;
将来自customers表中的ContactName是Helen Bennett或者John Steel并且CustomerID大于或等于16的所有CustomerID和ContactName记录插入suppliers表。
UPDATE
products
SET
UnitPrice = 0.9*UnitPrice
SupplierID = 7
(CategoryID = 2
CategoryID = 3);
将id为7的供应商提供的位于2,3类的产品价格调整为原来的90%。
DELETE
SupplierID = 24
(CategoryID = 6
CategoryID = 7);
将供应商ID为24 并且类别为6,7的产品从数据库中删掉。
原文链接:https://codingdict.com/