i'm trying the following MySQL query to fetch some data:
SELECT m.*, t.*
FROM memebers as m, telephone as t
INNER JOIN memeberFunctions as mf ON m.id = mf.memeber
INNER JOIN mitgliedTelephone as mt ON m.id = mt.memeber
WHERE mf.function = 32
But i always get the following error:
#1054 - Unknown column 'm.id' in 'on clause'
The column does exists and the query works fine with only one table (e.g. when i remove telephone)
Does anybody know what I do wrong?
It seems your requirement is to join
members
table but you are joining withtelephone
table. just change their order.Hope this helps you. Thank you!!
According to this link, you shouldn't mix up both notations when building up joins. The comma you are using to join
memebers as m, telephone as t
, and the subsequent calls toinner join
, are triggering the unknown column error.To deal with it, use
CROSS/INNER/LEFT JOIN
instead of commas.For pedagogic purpose, I'm adding the query as it, I think, should be:
Since you're not joining
t
andm
, the final result will be a cartesian product; you might want it to be revised.I Hope it helped.