如何解决 mysql 关联表查询问题?
设有表 a 和 b,表 a 的 outer_id 列连接表 b 的 id 列。现在需要查询表 a 的两组数据:
以下是查询这两组数据的 sql 语句:
查询第一组数据
select a.* from a a left join b b on b.id = a.outer_id where b.id is null or (b.id is not null and b.type != 99)
查询第二组数据
SELECT a.* FROM A a INNER JOIN B b ON b.id = a.outer_id AND b.type = 99
以上就是如何查询关联表中满足特定条件的两组数据?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号