gpt4 book ai didi

mysql - 是否可以将这 4 个查询合并为一个更高效的查询?

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

我希望我可以通过对数据库的一次查询来执行此操作:

// These four variables can change...
$weave = 10;
$grade = 4;
$model = 1;
$brim = 7;

现在我有这 4 个疑问:

SELECT WeaveDesc FROM store_item_weaves WHERE ID = '$weave' LIMIT 1
SELECT GradeDesc FROM store_item_grades WHERE ID = '$grade' LIMIT 1
SELECT ModelDesc FROM store_item_models WHERE ID = '$model' LIMIT 1
SELECT BrimDesc FROM store_item_brims WHERE ID = '$brim' LIMIT 1

是否可以将所有这些连接到一个更高效的查询中?

最佳答案

试试这个:

SELECT
(SELECT WeaveDesc FROM store_item_weaves WHERE ID = '$weave' LIMIT 1) AS WeaveDesc,
(SELECT GradeDesc FROM store_item_grades WHERE ID = '$grade' LIMIT 1) AS GradeDesc,
(SELECT ModelDesc FROM store_item_models WHERE ID = '$model' LIMIT 1) AS ModelDesc,
(SELECT BrimDesc FROM store_item_brims WHERE ID = '$brim' LIMIT 1) AS BrimDesc

关于mysql - 是否可以将这 4 个查询合并为一个更高效的查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32150201/

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