select relevance title based on tag similar to like with mysql

二次信任 提交于 2019-12-06 13:33:30
hims056

Try LIKE multiple time:

SELECT * FROM post
WHERE title LIKE '%some%'
AND title LIKE '%good%'

See this SQLFiddle

You can also join both tables like this:

SELECT post.post_id, title FROM Post
RIGHT JOIN Tags
ON post.post_id = tags.post_id
WHERE Tags.value IN ('some','good')
GROUP BY post.Post_ID
HAVING COUNT(*)>1;

See this SQLFiddle

Note: If we don't use HAVING clause, It will also return records where any single value exists

See this SQLFiddle

See the similar requirement with similar table structure.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!