gpt4 book ai didi

php - 在多个表中搜索 - 将结果作为一列给出

转载 作者:行者123 更新时间:2023-11-29 06:23:04 25 4
gpt4 key购买 nike

嘿 stackoverflow - 这是我的第一个问题。

我的 mySQLdb 中有 2 个表。

[tab_artist]
|id|artist|count

[tab_songtitle]
|id|songtitle|artistId

我尝试按照建议从 tab_artist.artist 和 tab_songtitle.songtitle 中进行选择,其中 searchclause = m

我已经尝试过了

SELECT artist, songtitle AS suggest 
FROM tab_artist, tab_songtitle
WHERE artist LIKE('m%') OR songtitle LIKE('m%')

但这给了我 2 栏,艺术家和建议

如果满足搜索,我需要艺术家给我,例如Metallic..但只有一次 - 但在歌曲标题中我需要所有以 met 开头的标题。

希望这对正确的专家有意义:)

最佳答案

工会应该做到这一点:

select artist    AS suggest from tab_artist    WHERE artist    LIKE 'm%'
union all
select songtitle AS suggest from tab_songtitle WHERE songtitle LIKE 'm%'

对于这种情况,我会使用union all,这样您就不会删除重复项,但如果例如 Metallica 有一张同名专辑,而您只想要单词出现一次。在这种情况下,union 会更合适。

关于php - 在多个表中搜索 - 将结果作为一列给出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1898698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com