当前位置: 首页 > 网络学院 > 服务端脚本教程 > SQL > SQL 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,..) |
LastName | FirstName | Address | City |
---|---|---|---|
Hansen | Ola | Timoteivn 10 | Sandnes |
Nordmann | Anna | Neset 18 | Sandnes |
Pettersen | Kari | Storgt 20 | Stavanger |
Svendson | Tove | Borgvn 23 | Sandnes |
To display the persons with LastName equal to "Hansen" or "Pettersen", use the following SQL:
要显示LastName为"Hansen"或是"Pettersen"的记录,则可以使用下面的这条SQL语句:
SELECT * FROM Persons |
结果:
LastName | FirstName | Address | City |
---|---|---|---|
Hansen | Ola | Timoteivn 10 | Sandnes |
Pettersen | Kari | Storgt 20 | Stavanger |