Andrew So
Andrew So

Reputation: 11

SQL sorting partial alphabetical order

I am having a hard time with SQL. I am using this demo of SQL here

but I cannot figure out how to list only companies that begin with A or F along with address and city. Can someone help me please?

Upvotes: 1

Views: 166

Answers (3)

Charles
Charles

Reputation: 342

You could use the like operator which would use an index if present.

SELECT CompanyName, ContactName, Address, City
FROM customers
WHERE CompanyName like '[af]%'

Upvotes: 1

http://msdn.microsoft.com/en-us/library/ms187748.aspx

where  lower(substring(title,0,1)) in ('a', 'f')

Upvotes: 0

Hogan
Hogan

Reputation: 70523

SELECT CompanyName, ContactName, Address, City
FROM customers
WHERE lower(substring(CompanyName,0,1)) in ('a','f')

Upvotes: 0

Related Questions