-1

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

1
  • What are you trying to obtain with LIMIT 5? Commented May 26, 2014 at 23:30

2 Answers 2

0
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

Sign up to request clarification or add additional context in comments.

3 Comments

ok LIMIT doesn´t work but, still throw an error on CREATE VIEW TEMAS_USUARIO: Incorrect syntax: CREATE VIEW must be the only statement in the batch
the tables are into BaseDeDatos, i can´t delete the line
If you are located in 'BaseDeDatos' database (executing: USE BaseDeDatos), the View will be created there.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.