当前位置: 首页 > 网络学院 > 服务端脚本教程 > SQL > SQL In

SQL
SQL Create View
SQL Server
SQL 速查
SQL 摘要
MYSQL 列类型存储需求

SQL In


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 895 ::
收藏到网摘: n/a

IN

The IN operator may be used if you know the exact value you want to return for at least one of the columns.
当你知道某栏目的准确值并想要返回其数据行,你可以使用IN操作符

SELECT column_name FROM table_name WHERE column_name IN (value1,value2,..)


Original Table (used in the examples)
初始表

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Nordmann Anna Neset 18 Sandnes
Pettersen Kari Storgt 20 Stavanger
Svendson Tove Borgvn 23 Sandnes


举例 1

To display the persons with LastName equal to "Hansen" or "Pettersen", use the following SQL:
要显示LastName为"Hansen"或是"Pettersen"的记录,则可以使用下面的这条SQL语句:

SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')

结果:

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Pettersen Kari Storgt 20 Stavanger

评论 (1) 1 All

登陆 | 还没注册?