I have a table Customer with Primary key customerNumber
. I also have a table table customerOrder that has a foreign key FK_customerNumber
to customerNumber
in the Customer table.
I know the customerNumber
and need to select
only order information related to that user.
I see a lot of tutorials using a JOIN like this
SELECT
projectNumber, orderNumber
FROM
`customerOrder` t1
INNER JOIN `customer` t2
ON t1.`FK_customerNumber` = t2.`customerNumber`
WHERE
t2.`customerNumber` = 50;
It's working but why can't I just select the FK? I get the same result. The value of the FK in customerOrder and PK in customer are the same.
This gives me the same result without JOIN
SELECT
projectNumber, orderNumber
FROM
`customerOrder`
WHERE
`FK_customerNumber` = 50;
I understand if I need info from both tables like this but now I only need info from the customerOrder
SELECT customerOrder.`projectNumber`, customer.`username`
FROM `customerOrder`
INNER JOIN customer ON customerOrder.`FK_customerNumber` = customer.`customerNumber`;