Martin Martin - 4 months ago 9
SQL Question

Trying to join three tables together and getting a syntax error

I am trying to write a postgres query that will join three tables together. I believe I have everything correct but when I run the query I get back a syntax error:

select
cwd_user.id,
cwd_user.user_name username,
cwd_user.email_address emailaddress,
cwd_user.active active
cwd_user.created_date created
cwd_membership.child_id
cwd_membership.parent_name groupname
licenserolesgroup.id
licenserolesgroup.license_role_name application
from
cwd_user
inner join cwd_membership on cwd_membership.child_id = cwd_user.id
inner join licenserolesgroup on cwd_membership.child_id = licenserolesgroup.id;


The query should be able to output:


  • userID

  • userName

  • emailAddress

  • active

  • createdDate

  • childID (used to match against the group table)

  • groupName

  • licenseID

  • application



Any help on this would be appreciated. I have not done a lot with joins. Trial by fire I guess!

Answer

You're missing a bunch of trailing commas. Try instead:

select
cwd_user.id,
cwd_user.user_name username,
cwd_user.email_address emailaddress,
cwd_user.active active,
cwd_user.created_date created,
cwd_membership.child_id,
cwd_membership.parent_name groupname,
licenserolesgroup.id,
licenserolesgroup.license_role_name application
from
cwd_user
inner join cwd_membership on cwd_membership.child_id = cwd_user.id
inner join licenserolesgroup on cwd_membership.child_id = licenserolesgroup.id;