Wildcard Question

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
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

Wildcard Question

Post by lazersam »

Hi all

I would like to search for any result in mysql. Something like

Code: Select all

select * from members where fname = "*"
Will that work?

Larry.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

select * from members where fname = "*" would be the same as
select * from members
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

Post by lazersam »

OK but the next bit might be

Code: Select all

select * from members where fname = "*" and sname = "Smith"
I need to put a wildcard in the query because I am building it from code. Will the "*" work? Is that the correct method for wildcard within a test result?

Thanks

Larry
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

fname LIKE "%"

I believe.

'course, if your going to use that then there's no point in adding fname to the where conditions..
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Nope, * won't work as a wildcard. Using * to mean "where it's equal to anything" is just the same as leaving out of the query.
So select * from members where fname = "*" and sname = "Smith" becomes select * from members where sname = "Smith"

% is mysql's wildcard, so you can do things like, select * from members where fname='J%' and it will find all rows where fname begins with the letter J, but using an empty wildcard statement is just the same as leaving out of the query.
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

Post by lazersam »

Thanks. :)

Larry.
Post Reply