gpt4 book ai didi

php - 连接具有不同 ID 的多个表

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

我有以下查询:

$cuttinglist_products_query = 
tep_db_query("select op.orders_products_id, op.orders_id, op.products_id, ".
"op.products_model, op.products_name, op.products_quantity, ".
"p.products_id from " . TABLE_ORDERS_PRODUCTS . " op " .
" left join " . TABLE_PRODUCTS . " p " .
" on (op.products_id = p.products_id) where orders_id = '" .
(int)$cuttinglist['orders_id'] . "'");

这将两个具有相同 ID 的表连接在一起。我将如何加入名为:

"TABLE_ORDERS_PRODUCTS_ATTRIBUTES" 

具有相同的 id:

"TABLE_ORDERS_PRODUCTS"

使用的 ID 是:

"orders_products_id"

最佳答案

只需添加另一个连接子句:

SELECT ...
FROM TABLE_ORDERS_PRODUCTS op
LEFT JOIN TABLE_PRODUCTS p ON op.products_id = p.products_id
LEFT JOIN TABLE_ORDERS_PRODUCTS_ATTRIBUTES pa ON op.products_id = pa.orders_products_id
WHERE ...

关于php - 连接具有不同 ID 的多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12251313/

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