gpt4 book ai didi

php - 我的 UNION ALL 查询需要建议

转载 作者:行者123 更新时间:2023-11-29 13:26:27 28 4
gpt4 key购买 nike

我的 table 是

user: userID -  userLogocontent: userID - contentID  - contentImagepromo: promoID - userID - promoImage

this is my query

SELECT userID,userLogo FROM user
WHERE userID=4
UNION ALL
SELECT userID,contentImage FROM content
WHERE userID=4
UNION ALL
SELECT userID,promoImage FROM promo
WHERE userID=4
ORDER BY userID

结果是

userID  userLogo4      ../images/user/000004.jpg 4      ../images/content/000003.jpg4      ../images/content/000004.jpg4      ../images/content/000005.jpg4      ../images/content/000006.jpg4      ../images/promo/000003.jpg4      ../images/promo/000004.jpg4      ../images/promo/000005.jpg

得到的结果和我想要的很相似,但是列标题不是我想要的

还有,关于 php.. 是否可以使用上面的查询来取消链接结果中的所有图像?

还有一个问题,讲效率,我的查询对数据库造成很大的负载吗?如果是,请给出建议或任何解决方案。

谢谢!

最佳答案

您可以使用第三列,以便您可以检查符合条件的图像类型

SELECT 
userID,
userLogo,
'userLogo' as Type
FROM user
WHERE userID=4

UNION ALL

SELECT
userID,
contentImage,
'contentImage' as Type
FROM content
WHERE userID=4

UNION ALL

SELECT
userID,
promoImage,
'promoImage' as Type
FROM promo
WHERE userID=4
ORDER BY userID

关于php - 我的 UNION ALL 查询需要建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064800/

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