[英]Selecting all from one table and joining to another
I have two tables, a manufacturer table with a primary of ManufacturerID and an atrribute of Manufacturer_Name, then iv'e got a product table with a primary of ProductID, a few attributes and the ManufacturerID foreign key.我有两个表,一个制造商表,主要是制造商 ID,属性是制造商名称,然后我得到了一个产品表,主要是产品 ID,一些属性和制造商 ID 外键。 I want to be able to display the manufacturer name before the product name with all the other product attributes there after on my output page but I cant get the join working, so far I have this query for the join:
我希望能够在我的输出页面上显示产品名称之前的制造商名称以及所有其他产品属性,但我无法让连接工作,到目前为止,我有这个连接查询:
$sql = "SELECT *
FROM product
LEFT JOIN Manufacturer_Name
ON product.ProductID = manufacturer.ManufacturerID
WHERE Product_Name
LIKE '%$searchq%' ";
Table name should be there with JOIN, also ManufacturerID will be the JOIN key.表名应该与 JOIN 一起存在,ManufacturerID 也将是 JOIN 键。 So the query will be:
所以查询将是:
$sql = "SELECT *
FROM product.
LEFT JOIN Manufacturer manufacturer
ON product.ManufacturerID = manufacturer.ManufacturerID
WHERE product.Product_Name
LIKE '%$searchq%' ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.