sql在phpmyadmin中合并2个表

时间:2012-10-12 16:08:01

标签: mysql

我有2个表,productsproducts_description。我希望这些字段来自productsproducts_idproducts_quantityproducts_modelproducts_imageproducts_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表。我该如何解决这个问题?

2 个答案:

答案 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