第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

mysql in語(yǔ)法介紹

標(biāo)簽:
MySQL

Summary: in this tutorial, you will learn how to use the MySQL IN operator that determines if a specified value matches any value a list or a subquery.

Introduction to the MySQL IN Operator

The IN operator allows you to determine if a specified value matches any one of a list or a subquery. The following illustrates the syntax of the IN operator.

SELECT column_list FROM table_name WHERE (expr|column) IN ('value1','value2',...)

In the query above:

  • You can use a column or an expression ( expr) with the IN operator in the WHERE clause of the SELECT statement.

  • The values in the list must be separated by a comma (,)

  • The IN operator can also be used in the WHERE clause of other statements such as INSERTUPDATEDELETE, etc.

The IN operator returns 1 if the value of the  column orthe result of the expr expression is equal to any value in the list, otherwise it returns 0.

When the values in the list are all constants:

  • First, MySQL evaluates the values based on the type of the column or result of the  expr.

  • Second, MySQL sorts the values.

  • Third, MySQL searches for values using binary search algorithm which is very fast.

Therefore a query that uses the IN operator with a list of constants will perform very fast.

If the expr or any value in the list is NULL, the IN operator returns NULL.

You can combine the IN operator with the NOT operator to determine if a value does not match any value in a list or a subquery.

Let’s practice with some examples of using the IN operator.

MySQL IN examples

If you want to find out all offices which locates in the U.S. and France, you can use the IN operator as the following query:

SELECT officeCode, city, phone FROM offices WHERE country IN ('USA','France')

mysql in example 1
You can achieve the same result with the OR operator as the following query:

SELECT officeCode, city, phone FROM offices WHERE country = 'USA' OR country = 'France'

In case the list has many values, you have to construct a very long statement with multiple OR operators. Hence the IN operator allows you to shorten the query and make the query more readable.

To get offices that does not locate in USA and France, you can use NOT IN in the WHERE clause as follows:

SELECT officeCode, city, phone FROM offices WHERE country NOT IN ('USA','France')

mysql in example 2

MySQL IN with subquery

The IN operator is often used with a subquery. For example, if you want to find order whose total amount is greater than $60K, you can use the IN operator as the following  query:

SELECT orderNumber,        customerNumber,        status,        shippedDate FROM orders  WHERE orderNumber IN ( SELECT orderNumber FROM   orderDetails GROUP BY orderNumber HAVING SUM(quantityOrdered * priceEach) > 60000)

MySQL IN operator with subquery

In this tutorial, we have shown you how to use MySQL IN operator to determine if a value matches any value in a list or a subquery.

Related Tutorials

原文链接:http://outofmemory.cn/mysql/sql-in

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消