Reputation: 494
SQL rookie here.
I'm trying to get the organisationtype name from my DB that links to a certain company.
Organisations has an ID Organisations_organisationtypes has organisation_id and a organisationtype_id Organisationtypes has organisationtype_id and the name of the type.
Currently I'm trying to do 2 inner joins to get there.
This step works fine:
select organisations.name, organisations_organisationtypes.organisationtype_id
from organisations
inner join organisations_organisationtypes
on
organisations.juridicalform_id=organisations_organisationtypes.organisationtype_id;
This gives me a list of COMPANY NAME - Organisationtype_id
So far so good.
Now I need to get the corresponding name for the organisationtype_id so I added following:
inner join organisationtypes
on organisations_organisationtypes.organisationtype_id=organisationtypes.id
and changed the first line to show me the name, the complete statement is now:
select organisations.name, organisations_organisationtypes.organisationtype_id, organisationtypes.name
from organisations
inner join organisations_organisationtypes
on organisations.juridicalform_id=organisations_organisationtypes.organisationtype_id;
inner join organisationtypes
on organisations_organisationtypes.organisationtype_id=organisationtypes.id
This gives me following errors:
[ERROR in query 1] Unknown column 'organisationtypes.name' in 'field list'
[ERROR in query 2] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inner join organisationtypes
on organisations_organisationtypes.organisationtype' at line 1
Upvotes: 0
Views: 62
Reputation: 77934
Did you noticed the ;
in below line that's why the error
on organisations.juridicalform_id=organisations_organisationtypes.organisationtype_id;
^....Here
inner join organisationtypes
Upvotes: 4