我有两个表,我将它们称为 table1 和 table2。Table1有2个字段,id和auth,table2也有两个字段,id和keywords。注意 table1 和 table2 的 id 匹配。这是我的查询:
SELECT id, MATCH(keywords) AGAINST('example') FROM table2 WHERE MATCH(keywords) AGAINST('example')
我将如何排除相同 id 的 auth (table1) 不是 1 的结果?
SELECT id, MATCH(keywords) AGAINST('example')
FROM table2 t2
WHERE MATCH(keywords) AGAINST('example')
AND NOT EXISTS (select 1 from table1 t1 where t1.id = t2.id and t1.auth != 1)
SELECT *
FROM table1 t1
INNER JOIN table2 t2
ON t1.id != t2.id