连接表并显示多个列

时间:2016-04-15 14:30:28

标签: sql amazon-redshift

我有以下查询:

SELECT
  timestamp
FROM seller_v2.dashboard_view dashboard
INNER JOIN seller_v2.users users
ON dashboard.user_id = users.id
ORDER BY timestamp DESC;

返回时间戳列表。我想添加更多列,如姓名和电子邮件。当我运行此查询时:

SELECT
  timestamp,
  name
FROM seller_v2.dashboard_view dashboard
INNER JOIN seller_v2.users users
ON dashboard.user_id = users.id
ORDER BY timestamp DESC;

我收到此错误: 错误:“或”附近的语法错误 第3行:时间戳,                      ^

如何添加其他列?

1 个答案:

答案 0 :(得分:2)

SELECT
  `timestamp`,
  name
FROM seller_v2.dashboard_view dashboard
INNER JOIN seller_v2.users users
ON dashboard.user_id = users.id
ORDER BY timestamp DESC;

我还建议使用别名。

所以dashboard.timestamp,dashboard.name(我猜他们是正确的别名)。