mysql 怎么判断一个表中的某一列有没有某个值

1、mysql中创建测试表,create table test_user(id int, name varchar(20));2、插入测试数据,insert into test_user values(1001,'jack');insert into test_user values(1002,'lucy');insert into test_user values(1003,'mike');insert into test_user values(1004,'john');insert into test...
mysql 怎么判断一个表中的某一列有没有某个值
1、mysql中创建测试表,create table test_user(id int, name varchar(20));

2、插入测试数据,
insert into test_user values(1001,'jack');
insert into test_user values(1002,'lucy');
insert into test_user values(1003,'mike');
insert into test_user values(1004,'john');
insert into test_user values(1005,'may');

3、查看表中所有数据,select * from test_user

4、编写sql,查询name列是否有jack名,
select * from test_user t where name = 'jack'

2019-11-15
可以用 select count(*) from table where username ='dpstill';
查询的结果=0 就不存在 >0 就存在

如果要用其他结果返回的话,可以用下面的

select case when COUNT(*)>0 then '存在' when count(*)=0 then '不存在' end from table where username ='dpstill'2015-11-06
mysql_connect('localhost', 'root', '11'); mysql_select_db('库名'); $field = mysql_query('Describe 表名 字段名'); $field = mysql_fetch_array($field); if($field[0]){ echo 'exist'; }else{ echo 'none'; }2015-04-04
SELECT * FROM TABLE WHERE 查询列名='你的值'?是不是这个意思2015-09-26
直接select where那个值不行么?再看看返回的数据集是否为空。2015-10-24
mengvlog 阅读 8 次 更新于 2025-07-20 20:48:06 我来答关注问题0
檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部