[英]Mysql search on multiple rows, multiple tables with multiple keywords
I would like to tweak the following mysql query, if possible: 如果可能,我想调整以下mysql查询:
SELECT * FROM artists,tags WHERE tags.tag_title LIKE '$q' AND artists.art_id=tags.art_id
$q
are the keywords entered by users $q
是用户输入的关键字 With this query tags.tag_title
have to match the exact search. 使用此查询,
tags.tag_title
必须匹配确切的搜索。 For example "alternative rock" will display all artists with the keyword "alternative rock" in the table tags. 例如,“ alternative rock”将在表格标签中显示所有带有关键字“ alternative rock”的艺术家。 It's ok.
没关系。
So, the question is that for the keyword "alternative rock" I would like to display ALSO the artists that have the keywords "alternative" and "rock" in different rows on the table tags but not the artists with the keywords "alternative" and "metal" or artists with the keywords "indie" and "rock". 因此,问题是,对于关键字“ alternative rock”,我还要在表格标签的不同行中显示具有关键字“ alternative”和“ rock”的艺术家,而不是关键字“ alternative”和“金属”或关键字为“独立”和“摇滚”的艺术家。
Does it makes sense? 有道理吗?
you look for something like this, 您正在寻找这样的东西,
SELECT * FROM artists
INNER JOIN tags
ON artists.art_id=tags.art_id
WHERE tags.tag_title LIKE '% $q1 %' OR tags.tag_title LIKE '% $q2 %'
q1 and q2 are keyword1 and keyword2 q1和q2分别为keyword1和keyword2
显然,这只是一个例子,但我认为您正在追求这样的东西:
SELECT * FROM artisits artist LEFT JOIN tags tag ON tag.artist_id = artist.id WHERE artist.name LIKE '$q' OR tag.name = $q
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.