MySQL LIKE String Comparisons

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
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

MySQL LIKE String Comparisons

Post by kendall »

HI

in a MySQL statement I am doing a

Code: Select all

WHERE [column] LIKE '%A'
so that the rows whos "column" data starts with "A" will be returned.

However this is not happening...in fact what is happening is that results are being returned that have "a" and "dam" but not "Adam"

What will cause the statement to act like this?

Kendall
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

You have it backwards if you want it to get every row that STARTS with A.

Code: Select all

LIKE 'A%'
% Basically Means Anything (Ex `*` Astrix), so you want to match A + anything.

What you have, is returning Everything that Ends in A. And this is case-insensitive.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

[SOLVED]

Post by kendall »

OOoohhhhh my bad! :oops:
Post Reply