0

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 
1
  • 1
    a comma, not a period, idk Commented Aug 17, 2015 at 9:55

1 Answer 1

4

Did you noticed the ; in below line that's why the error

on organisations.juridicalform_id=organisations_organisationtypes.organisationtype_id; ^....Here inner join organisationtypes 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I am officially blind. This returned me the correct list, with a lot of doubles. Select distinct solved that second problem.
That should be a separate question though; BTW why not just use DISTINCT operator to remove the dupes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.