1

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?

3

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.

  • Thanks Eduard, however I would need the subsequent distinct email addresses that end with gmail.com in another Data Extension. How would that work ? Can I use 'NOT IN' in that case? – Ashutosh Arora Sep 20 '17 at 10:07
  • Also, when I use your code, it gives me the following error: An error occurred while checking the query syntax. Errors: Invalid format specification: '%gmail.com'.'. Any suggestion? – Ashutosh Arora Sep 20 '17 at 10:10
  • Use single quotes instead of double quotes in your syntax '%gmail.com' – Eduard Sep 20 '17 at 10:12
  • Yes Eduard, I got that working.. Any suggestion on my first comment? Can I use NOT IN for that? – Ashutosh Arora Sep 20 '17 at 10:13
  • @AshutoshArora Why not? Honestly, didn't quite understand what you needed in your first comment. I think you should try it, and if it doesn't work then post another question here with clear explanation and what you already did to solve the problem. Anyway, answering a non-related question in comments is not a good idea. – Eduard Sep 20 '17 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.