十.Sql server中in的用法

In这个指令在sql中也是时常可见的,我们这里还是以实例为主进行讲解,它的语法格式:

SELECT "栏位名"
FROM "表格名"
WHERE "栏位名" IN('值一', '值二', ...)

假设我们有两个表格:

tb_Teachers_info

十.Sql server中in的用法

tb_City_info


然而我们要在tb_Teachers_info中找出所有来自American的教师姓名

SQL语句: select TeachersName from tb_Teachers_info whereCity in('American');

结果:

如果我们要从tb_Teachers_info中找出与tb_City_info中同名教师的TeachersId

SQL 语句: select TeachersId from tb_Teachers_info whereTeachersName in(selectTeachersName from tb_City_info);

结果:

下一节 SQL SERVERorder by的用法


你可能感兴趣的:(sql,server)