执行查询时出错选择左连接选择位置

时间:2017-05-20 02:13:51

标签: mysql select

我有两张桌子:

CREATE TABLE Student_registration (
    id INT AUTO_INCREMENT PRIMARY KEY,
    Name VARCHAR(255) NOT NULL,
    Contact VARCHAR(255) NOT NULL,
    regdatetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE timestamp_table (
    id INT AUTO_INCREMENT PRIMARY KEY,
    timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

执行此查询时:

select *
   from Student_registration
   LEFT JOIN (select count(*)
            from Student_registration)
    where RegDateTime > (select timestamp
                            from timestamp_table
                            where id= 1);

我收到此错误:

ERROR 1248 (42000): Every derived table must have its own alias

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您应该在此处添加别名(临时名称):

(select count(*) from Student_registration)

所以它会是这样的:

(select count(*) as total from Student_registration)

此处总计您可以用不同的名称命名。

使用JOIN时也可以使用 代替