NameSilo

SQL Help

Spaceship Spaceship
Watch
Hey guys,

I am trying to run a SQL command:

SELECT * FROM businesses WHERE website !='' ORDER BY company_name ASC;
SELECT * FROM businesses WHERE website ='' ORDER BY company_name ASC;

But I want this to be one SQL statement. Basically, I want to select businesses that have a website and order by company, then after order by company that does not have a website.

I don't want to do:
SELECT * FROM businesses ORDER BY website DESC, company_name ASC; because then it sorts by website reverse alphabetical.

Does this make sense? Any help would be great.

Thanks,
Shaun
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Use:

Code:
SELECT * FROM businesses ORDER BY website!='' DESC, company_name;
 
1
•••
Use:

Code:
SELECT * FROM businesses ORDER BY website!='' DESC, company_name;

Sweet. Thanks a lot!

---------- Post added at 01:13 AM ---------- Previous post was at 12:30 AM ----------

I have one more question. This is a little bit harder. I have a zipcode field. If someone searches a zipcode I need it to order by distance. My PHP script can do that, but it needs to order in that zipcode distance, followed by Website !='' DESC, company_name.

How would I do that?
 
0
•••
You'll need the SQL to determine the distance if you plan on having it order them all at once.

If you don't already have it, download the Zip code database which includes the coordinates of all US zip codes and take a look at the Google store locator tutorial for instructions on finding the distance using SQL.
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back