[Solved] Searching for sub-strings

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
davidtee1
Forum Newbie
Posts: 18
Joined: Fri Jun 10, 2005 2:41 am

[Solved] Searching for sub-strings

Post by davidtee1 »

I want to find all the records in a database that begin with "a", "b" etc and count the results.

Something like:

SELECT * FROM table WHERE word STARTS_WITH "a" (!)

I am sure this is trivial but I can't find the right WHERE clause to use.

Any help gratefully received.

David
Last edited by davidtee1 on Sat Sep 03, 2005 11:37 am, edited 1 time in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Code: Select all

SELECT count(*) FROM `table` WHERE `field` LIKE 'a%'
% is the wildcard, this returns the count where fields start with a
davidtee1
Forum Newbie
Posts: 18
Joined: Fri Jun 10, 2005 2:41 am

Post by davidtee1 »

Thanks - I knew it would easy, but couldn't find the wildcard.
Post Reply