i make a view in sql server and throw an error:
USE BaseDeDatos;
CREATE VIEW TEMAS_USUARIO
AS
SELECT TOP 5 t.id_userTopic, t.nameTopic, u.id_user, u.name
FROM Topic t, Users u
WHERE t.id_userTopic = u.id_group
ORDER BY t.id_topic DESC;
what is wrong whit the syntax?
error ---> CREATE VIEW TEMAS_USUARIO
can´t use LIMIT
USE BaseDeDatos
GO
CREATE VIEW TEMAS_USUARIO
AS
SELECT TOP 5 t.id_userTopic, t.nameTopic, u.id_user, u.name
FROM Topic t, Users u
WHERE t.id_userTopic = u.id_group
ORDER BY t.id_topic DESC;
The SQL SELECT TOP Clause:
SQL SERVER / MS ACCESS Syntax
SELECT TOP number|percent column_name(s)
FROM table_name;
MySQL Syntax
SELECT column_name(s)
FROM table_name
LIMIT number;
SQL SELECT TOP Clause explanation: Here
The syntax command of CREATE VIEW you have this:
The SELECT clauses in a view definition cannot include the following:
- An ORDER BY clause, unless there is also a TOP clause in the select list of the SELECT statement
Important note Important
The ORDER BY clause is used only to determine the rows that are returned by the TOP or OFFSET clause in the view definition. The ORDER BY clause does not guarantee ordered results when the view is queried, unless ORDER BY is also specified in the query itself.