MySql教程

mysql--表操作

本文主要是介绍mysql--表操作,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

条件查询:

-- 查询name = '测试' 或 email="test.com" 和id=1
select * from db where (name = '测试' or email="test.com")  and id=1;
-- 查找id在(1,2,3)
select * from db where id in (1,2,3);
-- 查找id在user表中的数据
select * from db where id in (select id from user);
-- 查找uer表id=5的语句是否存在,不存在则不查询db表
select * from db where exists (select * from user where id=5);
-- 查找uer表id=5的语句是否不存在,不存在则查询db表
select * from db where not exists (select * from user where id=5);
-- 查找db表中id大于2的数据且age大于5的数据
select * from (select * from db where id>2) as T where as.age > 5;
这篇关于mysql--表操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!