我在google上搜索了很多这样的内容,从过去的3天开始,我获得了许多解决方案,但对小型数据库的效率却不高;
如下所示
SELECT title FROM word o
WHERE NOT EXISTS (SELECT 1
FROM wp_posts c
WHERE c.post_title = o.title)
请为我提供一个有效的解决方案,以便像字典网站一样快速搜索。
答案 0 :(得分:2)
不幸的是MySQL不支持EXCEPT
语法,所以我在这里使用LEFT JOIN
:
SELECT title
FROM word o
/* try joining a wp_post based on title */
LEFT JOIN wp_posts c
ON c.post_title = o.title
/* LEFT JOIN couldn't join anything? Good for us: */
WHERE c.ID IS NULL /* you can use any NOT NULL field here, not just ID */
答案 1 :(得分:0)
尝试
SELECT title
FROM word
EXCEPT
SELECT post_title
FROM wp_posts
如果可行,则取决于您使用的DBMS,但是......
答案 2 :(得分:0)
您应该检查加入,可能它可以帮助您
SELECT title FROM word o
INNER JOIN wp_posts wp
ON p.title <> wp.post_title