检查值是否存在于MySQL表的列中?
让我们首先创建一个表-
mysql> create table DemoTable807( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(100), ClientCountryName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable807(ClientName,ClientCountryName) values('Chris','UK'); mysql> insert into DemoTable807(ClientName,ClientCountryName) values('David','AUS'); mysql> insert into DemoTable807(ClientName,ClientCountryName) values('Robert','US'); mysql> insert into DemoTable807(ClientName,ClientCountryName) values('Mike','ENG');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable807;
这将产生以下输出-
+----------+------------+-------------------+ | ClientId | ClientName | ClientCountryName | +----------+------------+-------------------+ | 1 | Chris | UK | | 2 | David | AUS | | 3 | Robert | US | | 4 | Mike | ENG | +----------+------------+-------------------+ 4 rows in set (0.00 sec)
以下是检查MySQL表的列中是否存在值的查询-
mysql> select *from DemoTable807 where ClientCountryName='US';
这将产生以下输出-
+----------+------------+-------------------+ | ClientId | ClientName | ClientCountryName | +----------+------------+-------------------+ | 3 | Robert | US | +----------+------------+-------------------+ 1 row in set (0.00 sec)