I’m trying to retrieve some data from the database, which need to be the top 10 of the agents with the highest score.
My Query:
SELECT AgentScores.agentID,
AgentScores.totalScore,
Agents.firstname,
Agents.lastname
FROM AgentScores
INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id
ORDER BY AgentScores.totalScore DESC
LIMIT 10
The inner joins are working. I’ve found the SELECT TOP 10
sql statement but.. I want the 10 agents with the highest score and not the first 10 id’s. As you can see I’m ordering on the totalscore.
Anyone has a clue how to fix this?
Error: Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. ) )
Thank you!
Zohar Peled
79.8k10 gold badges70 silver badges121 bronze badges
asked Jul 29, 2015 at 15:11
1
You have to use TOP clause instead of LIMIT
SELECT TOP 10 AgentScores.agentID, AgentScores.totalScore, Agents.firstname, Agents.lastname FROM AgentScores INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id ORDER BY AgentScores.totalScore DESC
answered Jul 29, 2015 at 15:18
1
In order to limit rows in MSSQL, you have to use SELECT TOP 10
…. instead of LIMIT 10
(limit is a MySQL clause, not MSSQL)
Zohar Peled
79.8k10 gold badges70 silver badges121 bronze badges
answered Jul 29, 2015 at 15:13
drmarvelousdrmarvelous
1,67310 silver badges18 bronze badges
4
I’m trying to retrieve some data from the database, which need to be the top 10 of the agents with the highest score.
My Query:
SELECT AgentScores.agentID,
AgentScores.totalScore,
Agents.firstname,
Agents.lastname
FROM AgentScores
INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id
ORDER BY AgentScores.totalScore DESC
LIMIT 10
The inner joins are working. I’ve found the SELECT TOP 10
sql statement but.. I want the 10 agents with the highest score and not the first 10 id’s. As you can see I’m ordering on the totalscore.
Anyone has a clue how to fix this?
Error: Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. ) )
Thank you!
Zohar Peled
79.8k10 gold badges70 silver badges121 bronze badges
asked Jul 29, 2015 at 15:11
1
You have to use TOP clause instead of LIMIT
SELECT TOP 10 AgentScores.agentID, AgentScores.totalScore, Agents.firstname, Agents.lastname FROM AgentScores INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id ORDER BY AgentScores.totalScore DESC
answered Jul 29, 2015 at 15:18
1
In order to limit rows in MSSQL, you have to use SELECT TOP 10
…. instead of LIMIT 10
(limit is a MySQL clause, not MSSQL)
Zohar Peled
79.8k10 gold badges70 silver badges121 bronze badges
answered Jul 29, 2015 at 15:13
drmarvelousdrmarvelous
1,67310 silver badges18 bronze badges
4
I am trying to query only 10 records and using LIMIT in query, but it is giving me the following error :
An error occurred while checking the query syntax. Errors: Incorrect
syntax near ‘LIMIT’.
Following is my query:
SELECT SubscriberKey, EmailAddress
FROM MASTER_IMPORT
WHERE EmailAddress LIKE "%gmail.com" LIMIT 10
Anything that I’m doing wrong here?
asked Sep 20, 2017 at 10:00
Ashutosh AroraAshutosh Arora
5881 gold badge11 silver badges29 bronze badges
SFMC uses T-SQL syntax, so you need to rewrite your query using the TOP expression instead of LIMIT.
SELECT TOP(10) SubscriberKey, EmailAddress
FROM MASTER_IMPORT
WHERE EmailAddress LIKE "%gmail.com"
Also refer to official documentation for more details on the TOP expression:
Limits the rows returned in a query result set to a specified number
of rows or percentage of rows.In a SELECT statement, always use an ORDER BY clause with the TOP
clause. This is the only way to predictably indicate which rows are
affected by TOP.
answered Sep 20, 2017 at 10:05
7
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
Я пытаюсь извлечь некоторые данные из базы данных, которые должны быть топ-10 агентов с наивысшим результатом.
Мой запрос:
SELECT AgentScores.agentID,
AgentScores.totalScore,
Agents.firstname,
Agents.lastname
FROM AgentScores
INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id
ORDER BY AgentScores.totalScore DESC
LIMIT 10
Внутренние соединения работают. Я нашел оператор SELECT TOP 10
sql, но.. Я хочу, чтобы 10 агентов с наивысшим результатом, а не первые 10 id. Как вы можете видеть, я заказываю на тотальном знаке.
Кто-нибудь знает, как это исправить?
Ошибка: Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. ) )
Спасибо!
I’m trying to retrieve some data from the database, which need to be the top 10 of the agents with the highest score.
My Query:
SELECT AgentScores.agentID,
AgentScores.totalScore,
Agents.firstname,
Agents.lastname
FROM AgentScores
INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id
ORDER BY AgentScores.totalScore DESC
LIMIT 10
The inner joins are working. I’ve found the SELECT TOP 10
sql statement but.. I want the 10 agents with the highest score and not the first 10 id’s. As you can see I’m ordering on the totalscore.
Anyone has a clue how to fix this?
Error: Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. ) )
Thank you!
Zohar Peled
78.8k10 gold badges69 silver badges120 bronze badges
asked Jul 29, 2015 at 15:11
1
You have to use TOP clause instead of LIMIT
SELECT TOP 10 AgentScores.agentID, AgentScores.totalScore, Agents.firstname, Agents.lastname FROM AgentScores INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id ORDER BY AgentScores.totalScore DESC
answered Jul 29, 2015 at 15:18
1
In order to limit rows in MSSQL, you have to use SELECT TOP 10
…. instead of LIMIT 10
(limit is a MySQL clause, not MSSQL)
Zohar Peled
78.8k10 gold badges69 silver badges120 bronze badges
answered Jul 29, 2015 at 15:13
drmarvelousdrmarvelous
1,64310 silver badges18 bronze badges
4
I’m trying to retrieve some data from the database, which need to be the top 10 of the agents with the highest score.
My Query:
SELECT AgentScores.agentID,
AgentScores.totalScore,
Agents.firstname,
Agents.lastname
FROM AgentScores
INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id
ORDER BY AgentScores.totalScore DESC
LIMIT 10
The inner joins are working. I’ve found the SELECT TOP 10
sql statement but.. I want the 10 agents with the highest score and not the first 10 id’s. As you can see I’m ordering on the totalscore.
Anyone has a clue how to fix this?
Error: Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. ) )
Thank you!
Zohar Peled
78.8k10 gold badges69 silver badges120 bronze badges
asked Jul 29, 2015 at 15:11
1
You have to use TOP clause instead of LIMIT
SELECT TOP 10 AgentScores.agentID, AgentScores.totalScore, Agents.firstname, Agents.lastname FROM AgentScores INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id ORDER BY AgentScores.totalScore DESC
answered Jul 29, 2015 at 15:18
1
In order to limit rows in MSSQL, you have to use SELECT TOP 10
…. instead of LIMIT 10
(limit is a MySQL clause, not MSSQL)
Zohar Peled
78.8k10 gold badges69 silver badges120 bronze badges
answered Jul 29, 2015 at 15:13
drmarvelousdrmarvelous
1,64310 silver badges18 bronze badges
4
- Remove From My Forums
-
Question
-
User-406225890 posted
SelectCommand=»SELECT [UserId], [HomeTown], [HomepageUrl], [Signature], [CreateDate] FROM [UserProfiles] ORDER BY [CreateDate] LIMIT 3,5″>
Thats my SQL statement, and its giving me an error saying.
The statement was working before the limit was added, so
SelectCommand=»SELECT [UserId], [HomeTown], [HomepageUrl], [Signature], [CreateDate] FROM [UserProfiles] ORDER BY [CreateDate]»
Incorrect syntax near ‘LIMIT’.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near ‘LIMIT’.
I’m pretty new to SQL, and i tried a few things but couldn’t fix it, can someone help me out? Thanks
Answers
-
User1096912014 posted
Your exact statement would be
select [UserId], [HomeTown], [HomepageUrl], [Signature], [CreateDate] from (select[UserId], [HomeTown], [HomepageUrl], [Signature], [CreateDate] , row_number() OVER (order by [CreateDate]) as RowNumber form [UserProfiles]) Derived where RowNumber between
4 and 9-
Marked as answer by
Thursday, October 7, 2021 12:00 AM
-
Marked as answer by
I am trying to query only 10 records and using LIMIT in query, but it is giving me the following error :
An error occurred while checking the query syntax. Errors: Incorrect
syntax near ‘LIMIT’.
Following is my query:
SELECT SubscriberKey, EmailAddress
FROM MASTER_IMPORT
WHERE EmailAddress LIKE "%gmail.com" LIMIT 10
Anything that I’m doing wrong here?
asked Sep 20, 2017 at 10:00
Ashutosh AroraAshutosh Arora
5781 gold badge11 silver badges29 bronze badges
SFMC uses T-SQL syntax, so you need to rewrite your query using the TOP expression instead of LIMIT.
SELECT TOP(10) SubscriberKey, EmailAddress
FROM MASTER_IMPORT
WHERE EmailAddress LIKE "%gmail.com"
Also refer to official documentation for more details on the TOP expression:
Limits the rows returned in a query result set to a specified number
of rows or percentage of rows.In a SELECT statement, always use an ORDER BY clause with the TOP
clause. This is the only way to predictably indicate which rows are
affected by TOP.
answered Sep 20, 2017 at 10:05
7
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
Я пытаюсь извлечь некоторые данные из базы данных, которые должны быть топ-10 агентов с наивысшим результатом.
Мой запрос:
SELECT AgentScores.agentID,
AgentScores.totalScore,
Agents.firstname,
Agents.lastname
FROM AgentScores
INNER JOIN Agents ON AgentScores.AgentId=Agents.Agent_id
ORDER BY AgentScores.totalScore DESC
LIMIT 10
Внутренние соединения работают. Я нашел оператор SELECT TOP 10
sql, но.. Я хочу, чтобы 10 агентов с наивысшим результатом, а не первые 10 id. Как вы можете видеть, я заказываю на тотальном знаке.
Кто-нибудь знает, как это исправить?
Ошибка: Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'LIMIT'. ) )
Спасибо!