首先用mysql建一张表:

CREATE TABLE Employee(
id int,
first_name VARCHAR(15),
last_name VARCHAR(15),
city VARCHAR(10),
);

然后向表中插入若干数据:

insert into Employee(id,first_name,last_name,City) values (1,\'Jason\',\'Martin\',\'Toronto\');
insert into Employee(id,first_name,last_name,City) values (2,\'Alison\',\'Mathews\',\'Vancouver\');
insert into Employee(id,first_name,last_name,City) values (3,\'James\',\'Smith\',\'Vancouver\');
insert into Employee(id,first_name,last_name,City) values (4,\'Celia\',\'Rice\',\'Vancouver\');
insert into Employee(id,first_name,last_name,City) values (5,\'David\',\'Larry\',\'New York\');

查询Employee表结

select *from Employee

结果集为: 

id first_name last_name city
1 Jason Martin Toronto
2 Alison Mathews Vancouver
3 James Smith Vancouver
4 Celia Rice Vancouver
5 David Larry New York

如果我们需要查询city为Vancouver的所有数据;此时可以使用where语句

select *from Employee where city=\'Vancouver\'

结果集为:

id first_name last_name city
2 Alison Mathews Vancouver
3 James Smith Vancouver
4 Celia Rice Vancouver

以上是mysql where 语句的使用实例,希望对大家学习有所帮助。

收藏 打印