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?

1
  • 2
    Can you please share your complet soql? Jun 24, 2016 at 14:49

1 Answer 1

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()
3
  • 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, 2016 at 15:26
  • FYI, Query Activities in SFMC follow Transact-SQL (SQLServer) syntax. Jun 24, 2016 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, 2016 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .