How can I select certain columns from the second and third tables using INNER JOIN
SELECT
*
FROM
1_packages_plu AS p
INNER JOIN
1_stock as s ON p.fk_products_id = s.fk_products_id
AND branch = 1
INNER JOIN
1_products AS j ON p.fk_products_id = j.id
WHERE
fk_packages_id = 54;
In the tables 1_stock
I only want to return the value of stock-repair
columns and in the 1_products
all I need is make,model columns
SELECT
p.* -- All columns from p
,
s.columnName -- Just that column from s
,
j.columnName -- And just that column from j
FROM
1_packages_plu AS p
INNER JOIN 1_stock as s
ON p.fk_products_id = s.fk_products_id
AND
branch = 1
INNER JOIN 1_products AS j
ON p.fk_products_id = j.id
WHERE
fk_packages_id = 54
You need (.) operator to access column:
SELECT
p.* ,
s.stock-repair,
j.make, j.model
FROM
1_packages_plu AS p
INNER JOIN 1_stock as s
ON p.fk_products_id = s.fk_products_id
AND branch = 1
INNER JOIN 1_products AS j
ON p.fk_products_id = j.id
WHERE
fk_packages_id = 54
ORDER BY p.colunmname
;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With