我正在尝试这样做
SELECT
table1.*,
table2.id as t2id
FROM
table1 as t1
INNER JOIN table2 as t2
ON t2.field1 = t1.field2
AND t1.field2 = 'value'
AND IF(SELECT COUNT(*) FROM table2 WHERE id = 10 > 0)
它错误说
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'SELECT COUNT(*) FROM table2 WHERE id = 10 > 0) LIMIT ' at line 1
我知道错误与 if 条件有关,因为当我删除它时,它可以工作,但我的想法是如果它不成功,select 将返回一个空值,即它没有在 table2 中找到 id 为 10 的表中的任何内容。