0

I'm trying to create a query activity in order to show, from a Data Extension, only the last 5 articles ids. I tried with the formula ORDER BY xxx DESC LIMIT 0,5 as in SQL but it is not working and it is returning this exception:

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified

How can I use ORDER BY in a Data Extension?

  • 2
    Can you please share your complet soql? – Sebastian Kessel Jun 24 '16 at 14:49
2

In SFMC, you'll need to specify top if you want to use an order by -- as the error suggests. For example if you want to select a random row in a Data Extension, you can use a query like this:

select top 1
column1
, column2
from DataExtension1
order by newid()
| improve this answer | |
  • Hi Adams, thanks to reply. This is the query that I used: SELECT Browser_History_Items* FROM Browser_History_Items ORDER BY Unique_Journey_ID DESC LIMIT 0,5 I will try with your suggestion and I will let you know. – M.Giorgio Jun 24 '16 at 15:26
  • FYI, Query Activities in SFMC follow Transact-SQL (SQLServer) syntax. – Adam Spriggs Jun 24 '16 at 15:52
  • Hi Adam, thanks a lot to reply. I couldn't find any solution to my question in other topics. I tried to use check and try in my Query Activity but everything seems not working. – M.Giorgio Jun 27 '16 at 12:39

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.