+ Start a Discussion
Lee SinLee Sin 

SOQL relational query order by

[SELECT Contact.FirstName, Contact.Account.Name from Contact order by Contact.Account.Name  limit 1000]

Why is this query not working
Best Answer chosen by Lee Sin
Roy LuoRoy Luo
First of all, save yourself some typing: don't need to have Contact. all over the place since the query is in Contact context.

try this:
SELECT FirstName, Account.Name from Contact where Account.Name!=null order by Account.Name  limit 1000

All Answers

Parvinder SinghParvinder Singh
Are you getting any errors, like non selective query on a very large data set?
Parvinder SinghParvinder Singh
If you are getting that error its becasue your SOQL does not have any selective conditions, read More Efficient SOQL Queries in https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm
Roy LuoRoy Luo
First of all, save yourself some typing: don't need to have Contact. all over the place since the query is in Contact context.

try this:
SELECT FirstName, Account.Name from Contact where Account.Name!=null order by Account.Name  limit 1000
This was selected as the best answer
Roy LuoRoy Luo
Likely your top 1000 entries have no or blank AccountName