尝试将三个表连接在一起并获得语法错误

时间:2016-07-21 23:56:59

标签: sql postgresql inner-join

我正在尝试编写一个将三个表连接在一起的postgres查询。我相信我有一切正确,但当我运行查询时,我得到一个语法错误:

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;

查询应该能够输出:

  • 用户ID
  • 的userName
  • EMAILADDRESS
  • 活性
  • createdDate
  • childID(用于匹配组表)
  • 组名
  • licenseID
  • 应用

对此有任何帮助将不胜感激。加入时我没有做太多。我猜是试着火!

2 个答案:

答案 0 :(得分:0)

你错过了一堆尾随逗号。请尝试改为:

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;

答案 1 :(得分:0)

我在帖子中没有看到任何错误消息。我认为这是因为缺少','每个字段末尾的(逗号)字符?

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;