Page 1 of 1

Wildcard Question

Posted: Sat Jun 05, 2004 3:02 am
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.

Posted: Sat Jun 05, 2004 3:05 am
by markl999
select * from members where fname = "*" would be the same as
select * from members

Posted: Sat Jun 05, 2004 3:13 am
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

Posted: Sat Jun 05, 2004 3:15 am
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..

Posted: Sat Jun 05, 2004 3:17 am
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.

Posted: Sat Jun 05, 2004 3:20 am
by lazersam
Thanks. :)

Larry.