teamg
teamg

Reputation: 733

Why is MySQL matching strings and integers in a way I don't expect?

I have a mysql database with the following column:

    +-----+
    | vpn |
    +-----+
    | 11a |

When I use query:

SELECT vpn FROM vpn_map  WHERE vpn=11;

It returns:

    +-----+
    | vpn |
    +-----+
    | 11a |

But if I query:

Select VPN from vpn_map where vpn=lla;

I get:

ERROR 1054 (42S22): Unknown column '11a' in 'where clause'

Why doesn't the previous query match? It will match if I do:

Select VPN from vpn_map where vpn='lla';

But then vpn='11' won't match anything. What am I missing here?

Upvotes: 1

Views: 162

Answers (1)

René Höhle
René Höhle

Reputation: 27295

11a is not an integer and you have so use " around them otherwise you get an error.

SELECT vpn FROM vpn_map WHERE vpn="lla";

Upvotes: 1

Related Questions