Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

SQL Help

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Use:

Code:
SELECT * FROM businesses ORDER BY website!='' DESC, company_name;
 
1
Close
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
Close
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
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back