0

How would you go about getting the most recent date from a table? I've been trying to use the clause order by but I get back the following error: "An error occurred while checking the query syntax. Errors: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified."

FROM Account_Salesforce B   
Inner JOIN Contact_Salesforce A   
ON A.AccountId = B.Id
Left Join  Movimento__c_Salesforce C
on C.Cliente__c = B.Id
WHERE   B.KPIUltimoSoggiornoAnno__c >= 2021 
ORDER BY C.Data_Inserimento__c desc
3
  • 1
    Welcome to SFSE! This appears to be generic SQL, not Salesforce SOQL, so would likely be more on topic at Stack Overflow.
    – David Reed
    Commented Jan 11, 2023 at 17:32
  • 1
    Perhaps it's for marketing-cloud (and is missing a tag)?
    – Phil W
    Commented Jan 11, 2023 at 17:42
  • @DavidReed it's Sql and thats why it's probably not working on Marketing Cloud. I opened the question due to I'd like to know the correct sintax on SOQL. Commented Jan 12, 2023 at 10:40

1 Answer 1

2

I think it's easiest just to use top 100 percent like this:

select top 100 percent 
b.id
FROM Account_Salesforce B   
Inner JOIN Contact_Salesforce A ON A.AccountId = B.Id
Left Join  Movimento__c_Salesforce C on C.Cliente__c = B.Id
WHERE B.KPIUltimoSoggiornoAnno__c >= 2021 
ORDER BY C.Data_Inserimento__c desc

Note that top doesn't work in Query Studio, but it does in a Query Activity.

You must log in to answer this question.

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