Home>

The table has
1st shouhin
hinmei kakaku tenmei
Apple 500 fruit market
Strawberry 600 fruit market
Lettuce 100 vegetable market

The second haisou
tenmei souko
Fruit market tokyo
Vegetable market osaka

From a table such as


Hand only hinmei's "apple"
I want to link based on the "fruit market", the tenmei of "apples"

As a result
hinmei kakaku tenmei souko
Apple 500 fruit market tokyo
Strawberry 600 fruit market tokyo

$hinmei = "apple";
SELECT * FROM shouhin INNER JOIN haisou
  ON haisou.tenmei = shouhin.tenmei
WHERE hinmei = (: hinmei)


It cannot be realized in the above state
Please tell me how to link the fruit market based on the value of apples

  • Answer # 1

    If you answer another question, you have misread the question and made a deletion request.

    SELECT shouhin. *, haisou.souko FROM shouhin INNER JOIN haisou
    WHERE shouhin.tenmei = haisou.tenmei
      AND shouhin.tenmei = (
        SELECT tenmei FROM shouhin WHERE hinmei = "apple"
      )


    If you use a subquery like this, you can do what you want.

    Operation sample

  • Answer # 2

      

    "Apple" category "fruit"

    Create a table for categories and normalize it