我有2个表,products
和products_description
。我希望这些字段来自products
:products_id
,products_quantity
,products_model
,products_image
和products_price
。
我想加入来自products_description
products_description
我到目前为止的SQL是
SELECT products.products_id, products.products_quantity, products.products_image, products.products_price, products_image
FROM products
INNER JOIN products_description
ON products.products_id=products_description.products_id
ORDER BY products.products_id
我的结果只是从产品表中获取的字段名称,而不是来自
products_description
表。我该如何解决这个问题?
答案 0 :(得分:0)
您的JOIN
是正确的,但您没有从products_description
表中选择任何内容。
更新SELECT
以包含products_description
中的列(替换正确的列名称)。
SELECT products.products_id, ..., products_description.column_name, products_description.column_name2, ...
答案 1 :(得分:0)
您忘记在SELECT语句中编写products_description.*
(将从products_description表中获取所有列)。
SELECT products.products_id, products.products_quantity, products.products_image, products.products_price, products_image, products_description.*
FROM products
INNER JOIN products_description
ON products.products_id=products_description.products_id
ORDER BY products.products_id