扫码关注官方订阅号
我想要像上图那样在两个表里面查询username,只有其中一个表有这个数据就返回true,但是MySQL判断必须两个表都有才返回true。
请问有什么办法可以实现这样的查询呢?(两个表中任何一个表有数据则返回true)
光阴似箭催人老,日月如移越少年。
select * from user_agent, user_cleck where user_agent.username = 'huibao' or user_clerk.username = 'huibao'这样可以吗?
select * from user_agent, user_cleck where user_agent.username = 'huibao' or user_clerk.username = 'huibao'
select * from table1, table2 是多表联合查询,题主的情况只是两个单表查询的结果取合集,应该用 UNION。
select * from table1, table2
1、结果取合集
select * from user_agent where username='{$username}' union all select * from user_clerk where username='{$username}';
2、结果取合集,并去掉重复项
select * from user_agent where username='{$username}' union select * from user_clerk where username='{$username}';
题主的情况,两种都可以。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
select * from user_agent, user_cleck where user_agent.username = 'huibao' or user_clerk.username = 'huibao'这样可以吗?select * from table1, table2是多表联合查询,题主的情况只是两个单表查询的结果取合集,应该用 UNION。1、结果取合集
2、结果取合集,并去掉重复项
题主的情况,两种都可以。