我的桌子是
user: userID - userLogo content: userID - contentID - contentImage promo: promoID - userID - promoImage
这是我的查询
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 userLogo 4 ../images/user/000004.jpg 4 ../images/content/000003.jpg 4 ../images/content/000004.jpg 4 ../images/content/000005.jpg 4 ../images/content/000006.jpg 4 ../images/promo/000003.jpg 4 ../images/promo/000004.jpg 4 ../images/promo/000005.jpg
获得的结果与我想要的非常相似,但是列标题不是我想要的
并且,关于php ..是否可以使用上面的查询来取消链接结果中的所有图像?
还有一个问题,谈论效率,我的查询是否会给数据库带来沉重负担?如果是,请提供建议或任何解决方案。
谢谢!
答案 0 :(得分:1)
您可以使用第三列,以便检查具有条件的图像类型
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
答案 1 :(得分:0)
"SELECT userID AS YOUR_CHOICE,userLogo AS 'your_choice' 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"