Multiple INNER JOIN from the same table Multiple INNER JOIN from the same table sqlite sqlite

Multiple INNER JOIN from the same table


You should specify different aliases for your tables . you are calling all of them m.

SELECT m1.MetalCode as 'Metal1', m2.MetalCode as 'Metal2',m3.MetalCode as 'Metal3'FROM Item as kINNER JOIN Metals AS m1 ON m1.metalID=k.metal1 INNER JOIN Metals AS m2 ON m2.metalID=k.metal2INNER JOIN Metals AS m3 ON m3.metalID=k.metal3WHERE k.ItemID=?


Well, not completely wrong. ;)

Wherever you have "INNER JOIN Metals AS m", m needs to be something unique (not m every time).

Try something like this (not tested):

SELECT m1.MetalCode as 'Metal1', m2.MetalCode as 'Metal2', m3.MetalCode as 'Metal3'FROM Item as kINNER JOIN Metals AS m1 ON m1.metalID=k.metal1 INNER JOIN Metals AS m2 ON m2.metalID=k.metal2INNER JOIN Metals AS m3 ON m3.metalID=k.metal3WHERE k.ItemID=?


try this:

SELECT m.MetalCode as 'Metal1', n.MetalCode as 'Metal2'o.MetalCode as 'Metal3'FROM Item as k INNER JOIN Metals AS m ON m.metalID=k.metal1         INNER JOIN Metals AS n ON n.metalID=k.metal2        INNER JOIN Metals AS o ON o.metalID=k.metal3WHERE k.ItemID=?