MYSQL在两列中选择一列 [英] MYSQL Select on two values one column
本文介绍了MYSQL在两列中选择一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在表中有两行,其中有一个等值。
TABLE
-----
articleId
keywordId
现在我需要选择一篇文章,其中包含关键字Id = 1以及关键字Id = 12。
每个关键字的链接都有自己的记录。
如何才能做一个选择查询来了解是否有文章匹配两个关键字? / b>
解决方案
试试这个:
SELECT *
FROM tablename
WHERE keywordId IN(1,12)
GROUP BY articleId
HAVING COUNT(*)= 2;
I need to select a row from my mysql table.
In the table there are two rows with one equal value.
TABLE
-----
articleId
keywordId
Now I need to select an article, that has keyword Id = 1, as well as keyword Id = 12.
Every link to a keyword has its own record.
How can I do one select query to know, if there is an article, that matches the two keywords?
解决方案
Try this:
SELECT *
FROM tablename
WHERE keywordId IN (1, 12)
GROUP BY articleId
HAVING COUNT(*) = 2;
Check the SQL FIDDLE DEMO
这篇关于MYSQL在两列中选择一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文