0
How to use INNER JOIN
with WHERE
?
I’m making a INNER JOIN
with 3 tables.
I need a WHERE
to return only one record. I am trying as follows:
SELECT `*` FROM (`tabela1`)
INNER JOIN `tabela2` ON `tabela1`.`id` = `tabela2`.`id`
INNER JOIN `tabela3` ON `tabela2`.`id` = `tabela3`.`id`
WHERE `tabela1`.`id` = 12;
Only Mysql returns this error:
Column 'id_militar' in Where clause is ambiguous
I want to receive only one record on INNER JOIN
, not all of the table. How do I?
You really put
nome_tabela.id_militar
on Where? Because this error presented means that there isid_militar
in more than one of the selected tables and he does not know which one you are comparing.– Luis Henrique
Are you specifying from which table is the "id_military" field? Because it seems to exist in more than one table and you’re not specifying which one it is.
– Guilherme Branco Stracini
Exactly what you said, I was making two comparisons with the same value (table.id). Thanks, problems solved
– Celson Rodrigues