英文:
PostgreSQL multiple join issue
问题
ERROR: 第二个INNER JOIN 语法有问题。要在第一个INNER JOIN 结束后加一个分号,然后才能开始第二个INNER JOIN。以下是修正后的代码:
SELECT
access.id,
access.user_id,
access.device_id,
access.origin,
access.creation_date
FROM
table1 access
INNER JOIN (
SELECT
device_id,
MAX (creation_date) AS creation_date
FROM
table1
GROUP BY
device_id
) gaccess ON access.device_id = gaccess.device_id
AND access.creation_date = gaccess.creation_date
INNER JOIN
table2 AS jobinfo
ON gaccess.device_id = jobinfo.id;
希望这有帮助!
英文:
Iam trying to create query with multiple JOINS, but Im receiving error message regarding syntax on second JOIN.
ERROR: syntax error at or near "INNER"
LINE 19: INNER JOIN table2 AS jobinfo ON gaccess....
^
SQL state: 42601
Character: 418
Can you help me what am I doing wrong?
SELECT
access.id,
access.user_id,
access.device_id,
access.origin,
access.creation_date
FROM
table1 access
INNER JOIN (
SELECT
device_id,
MAX (creation_date) AS creation_date
FROM
table1
GROUP BY
device_id
) gaccess ON access.device_id = gaccess.device_id
AND access.creation_date = gaccess.creation_date;
INNER JOIN
table2 AS jobinfo
ON gaccess.device_id = jobinfo.id
答案1
得分: 2
你有一个问题 - 在倒数第二个 INNER JOIN
之前有一个 ;
- 你需要移除它。
SELECT access.id,
access.user_id,
access.device_id,
access.origin,
access.creation_date
FROM table1 access
INNER JOIN
(
SELECT device_id
,MAX(creation_date) AS creation_date
FROM table1
GROUP BY device_id
) gaccess
ON access.device_id = gaccess.device_id
AND access.creation_date = gaccess.creation_date
INNER JOIN table2 AS jobinfo
ON gaccess.device_id = jobinfo.id;
英文:
You have a type - before the last INNER JOIN
there is ;
- you need to remove it.
SELECT access.id,
access.user_id,
access.device_id,
access.origin,
access.creation_date
FROM table1 access
INNER JOIN
(
SELECT device_id
,MAX(creation_date) AS creation_date
FROM table1
GROUP BY device_id
) gaccess
ON access.device_id = gaccess.device_id
AND access.creation_date = gaccess.creation_date
INNER JOIN table2 AS jobinfo
ON gaccess.device_id = jobinfo.id;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论