Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I create this table in SQL?

CREATE TABLE AverageStudents 
AS 
     (SELECT * 
      FROM StudentData 
      WHERE GPA > 3.0);

I keep getting the error

Incorrect syntax near the keyword 'AS'.

Does my simple code look alright to you? I really want a table (not a view, thanks for suggestion though).

like image 319
phan Avatar asked Mar 28 '26 18:03

phan


2 Answers

Try this one -

SELECT *
INTO AverageStudents 
FROM StudentData 
WHERE GPA > 3.0

Or this -

CREATE VIEW AverageStudents 
AS
     SELECT *
     FROM StudentData 
     WHERE GPA > 3.0
like image 53
Devart Avatar answered Mar 31 '26 05:03

Devart


I think you're looking for a view:

CREATE VIEW AverageStudents AS
  SELECT * 
  FROM StudentData 
  WHERE GPA > 3.0;
like image 23
bhamby Avatar answered Mar 31 '26 04:03

bhamby