0

I have 2 tables:

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
);

When I perform this query:

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

I get this error:

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

How do I fix this?

Pang
  • 9,564
  • 146
  • 81
  • 122
lyphuong
  • 3
  • 2

1 Answers1

0

You should add alias (temporary name) here:

(select count(*) from Student_registration)

So it would be like this:

(select count(*) as total from Student_registration)

Here its total you can name it differently.

And also use on instead of where when using JOIN.

Denis
  • 105
  • 5
  • It work with query: select count(*) as total from Student_registration; But its not work with query complex: select * from Student_registration LEFT JOIN (select count(*) as total from Student_registration) where RegDateTime > (select timestamp from timestamp_table where id= 1); – lyphuong May 20 '17 at 03:41
  • maybe try to use 'on' instead of 'where' – Denis May 20 '17 at 03:51
  • Nearly. Want to try again? – Strawberry May 20 '17 at 06:54
  • It work, thank Denis and Strawberry help me this problem : select * from Student_registration LEFT JOIN (select count(*) as total from Student_registration) as table2 on RegDateTime > (select timestamp from timestamp_table where id= 1); – lyphuong May 20 '17 at 22:11