knex.js 中的 .where() 和 .where Exists() 有什么区别?
What is the diffrence between .where() and .whereExists() in knex.js?
我认为这是同一个问题,就好像在问 WHERE 和 WHERE EXIST 之间有什么区别?!
.where()
创建一个 WHERE
子句,如:
select `id` from `users` where `first_name` = 'Test' and `last_name` = 'User'
此子句用于开始查询的条件部分。
.whereExists()
创建一个 WHERE EXISTS
子句,如:
select * from `users` where exists (select * from `accounts` where users.account_id = accounts.id)
此子句测试子查询中是否存在行。在某些情况下,它比使用 JOIN
更快,因为它不会将整个 table 连接到更高级别的 table(在 FROM
子句中)。更多信息请访问 this other SO post
(这些示例查询取自 knex website)
披露:我为 EnterpriseDB (EDB)
工作
我认为这是同一个问题,就好像在问 WHERE 和 WHERE EXIST 之间有什么区别?!
.where()
创建一个 WHERE
子句,如:
select `id` from `users` where `first_name` = 'Test' and `last_name` = 'User'
此子句用于开始查询的条件部分。
.whereExists()
创建一个 WHERE EXISTS
子句,如:
select * from `users` where exists (select * from `accounts` where users.account_id = accounts.id)
此子句测试子查询中是否存在行。在某些情况下,它比使用 JOIN
更快,因为它不会将整个 table 连接到更高级别的 table(在 FROM
子句中)。更多信息请访问 this other SO post
(这些示例查询取自 knex website)
披露:我为 EnterpriseDB (EDB)
工作