哪些标签不在数据库中? [英] Which tags are not in the database?
本文介绍了哪些标签不在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出了一组用户指定的标签,如何确定带有1条SQL语句的标签表中哪些不是?
Given a collection of user specified tags how do I determine which ones are not in the tags table with 1 SQL Statement?
假设表架构为tags (id, tag)
,并且我使用的是mysql,但我不知道有没有优化.
Assuming a table schema tags (id, tag)
and I'm using mysql, if there's an optimization I'm unaware of.
谢谢
推荐答案
SELECT Tag
FROM UserSpecifiedTags
LEFT OUTER JOIN AllTags ON UserSpecifiedTags.Tag = AllTags.Tag
WHERE AllTags.Tag IS NULL
这应该返回您想要的.以我的经验,执行联接并查找不匹配的行比使用IN
运算符要快 .
This should return what you want. In my experience, executing a join and looking for rows which don't have a match is much quicker than using the IN
operator.
这篇关于哪些标签不在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文