如何在SQL中使用JOIN语句

发布于 2025-02-11 16:20:36 字数 367 浏览 2 评论 0原文

我正在研究一个具有两个表格的员工_DATA数据集;员工和部门。我正在尝试使用Department_ID作为主要密钥加入员工表的数据到部门表。它不断给我一个错误消息。请我在哪里想念它?

SELECT name AS departments_name, 
(
  SELECT name AS employees_name,
FROM `my-first-analysis.employee_data.employees`
)
FROM `my-first-analysis.employee_data.departments` 
JOIN departments ON departments.department_id = employees.department_id

I'm working on an employee_data dataset which has two tables; employees and departments. I'm trying to join data from the employee table to the departments table using department_id as the primary key. It keeps giving me an error message. Please where am I missing it?

SELECT name AS departments_name, 
(
  SELECT name AS employees_name,
FROM `my-first-analysis.employee_data.employees`
)
FROM `my-first-analysis.employee_data.departments` 
JOIN departments ON departments.department_id = employees.department_id

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

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

发布评论

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

评论(1

夜空下最亮的亮点 2025-02-18 16:20:36

像这样:

SELECT departments.name AS departments_name,
      employees.name AS employees_name,
From employees
Left JOIN departments ON departments.department_id = employees.department_id

Like this:

SELECT departments.name AS departments_name,
      employees.name AS employees_name,
From employees
Left JOIN departments ON departments.department_id = employees.department_id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文