Problem Description
I'm writing application which is working with database, it select some data from the database and shows it to the user in the list view. There are some criterias which I must keep while selecting items from the database.
- In the database I keep some location (latitude and longitude), when selecting items I must get my current position and order items from the closer to me to the farther.
- In the database I have TOP companies which must be always first in the list independent on their location (latitude and longitude)
Question
So I need some query which will select all this information in the right ordering at once, because currently I am using 3 queries to do that.
Current solution
Here are the queries which I use to select all information which I need, currently I select all items add them to array and only after that I sort them in the array according to the distance.
SELECT TOP COMPANIES
select CompanyInfo._id, CompanyInfo.name_en, ContactInfo.telephones, ContactInfo.location, CompanyInfo.websites, ContactInfo.address_en, ContactInfo.location, ContactInfo.position, TopFirmsByCode.Level, ContactInfo.name_en from CompanyInfo, ContactInfo, TopFirmsByCode where CompanyInfo._id=TopFirmsByCode.RegNo AND CompanyInfo._id=ContactInfo._id AND TopFirmsByCode.Code = 452 order by TopFirmsByCode.Level ASC, CompanyInfo.rating_ordering_en ASC`SELECT THE REST OF COMPANIES ORDERED BY DISTANCE
select CompanyInfo._id, CompanyInfo.name_en, ContactInfo.telephones,ContactInfo.location,CompanyInfo.websites,ContactInfo.address_en,ContactInfo.location, ContactInfo.position, ContactInfo.name_en from CompanyInfo, ContactInfo where CompanyInfo._id=ContactInfo._id AND CompanyInfo.category_codes LIKE %547% order by ContactInfo.location ASC