将同一个表连接到多个字段

发布于 2024-11-17 12:02:58 字数 525 浏览 1 评论 0原文

我有这个 SQL,我正在尝试将人员登录名表加入到包含多个用户 ID 的任务表中,

  SELECT Task.TaskID
      ,Project.Project
      ,Task.Task
      ,Task.Description
      ,Task.OwnerLoginID //shown as Login.UserName
      ,Task.SubmitterID //shown as Login.UserName
      ,Task.IsVisible
  FROM Task
  INNER JOIN Project ON Task.ProjectID = Project.ProjectID
  /*
  INNER JOIN Login ON Task.SubmitterID = Login.LoginID
  INNER JOIN Login ON Task.OwnerLoginID = Login.LoginID
  */
  WHERE IsVisible = 1

但在底部的注释行中出现错误,我哪里出错了?

I have this SQL and i am trying to join a table of people's login names to a table of tasks that contains several user ids

  SELECT Task.TaskID
      ,Project.Project
      ,Task.Task
      ,Task.Description
      ,Task.OwnerLoginID //shown as Login.UserName
      ,Task.SubmitterID //shown as Login.UserName
      ,Task.IsVisible
  FROM Task
  INNER JOIN Project ON Task.ProjectID = Project.ProjectID
  /*
  INNER JOIN Login ON Task.SubmitterID = Login.LoginID
  INNER JOIN Login ON Task.OwnerLoginID = Login.LoginID
  */
  WHERE IsVisible = 1

i get an error in the commented out lines at the bottom where am i going wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕头说它不想醒 2024-11-24 12:02:58

尝试为表分配别名,例如

SELECT Task.TaskID
      ,Project.Project
      ,Task.Task
      ,Task.Description
      ,submitted.UserName
      ,owner.UserName
      ,Task.IsVisible
  FROM Task
  INNER JOIN Project ON Task.ProjectID = Project.ProjectID
  INNER JOIN Login submitted ON Task.SubmitterID = submitted.LoginID
  INNER JOIN Login owner ON Task.OwnerLoginID = owner.LoginID
  WHERE IsVisible = 1

try assigning alias names to the tables e.g.

SELECT Task.TaskID
      ,Project.Project
      ,Task.Task
      ,Task.Description
      ,submitted.UserName
      ,owner.UserName
      ,Task.IsVisible
  FROM Task
  INNER JOIN Project ON Task.ProjectID = Project.ProjectID
  INNER JOIN Login submitted ON Task.SubmitterID = submitted.LoginID
  INNER JOIN Login owner ON Task.OwnerLoginID = owner.LoginID
  WHERE IsVisible = 1
从来不烧饼 2024-11-24 12:02:58

如果你想 JOIN 同一张桌子意味着,像这样给予

  INNER JOIN Login L ON Task.SubmitterID = L.LoginID
  INNER JOIN Login LA ON Task.OwnerLoginID = LA.LoginID

If you want to JOIN the same table means, Give like this

  INNER JOIN Login L ON Task.SubmitterID = L.LoginID
  INNER JOIN Login LA ON Task.OwnerLoginID = LA.LoginID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文