我想要的这个查询将创建 SQL 连接方式。
Select count(*) as testOffers From table1 Where posted_test_id in (Select post_test_id From
table2 Where user_id = 367) AND is_test_offer=1;
最佳答案
这相当于:
Select count(*) as testOffers
From table1 t1 join
(Select distinct post_test_id
From table2
Where user_id = 367
) t2
on t1.posted_test_id = t2.post_test_id
where t1.is_test_offer = 1;
请注意,select unique
在子查询中非常重要,因为两者在语义上是等效的。 in
不需要这样做,因为重复并不重要。
在您的特定情况下,可能不需要select unique
。这是因为子查询不返回重复项。
关于mysql - 如何用连接方式解决这个子查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58658006/