We help IT Professionals succeed at work.

select from more than one column mysql

Luey
Luey asked
on
Medium Priority
569 Views
Last Modified: 2012-03-10
Is it possible to select from more than one column in sql.
What i am trying to do is build a search where if I type a first name or a last name in my search form I can retrieve data checking two different columns.  Is that possible.  This code does not work but it may give you an idea of what I am trying to do.  I want to look in mem_first_name or mem_last_name and retrieve all that match my search.

"SELECT * FROM members WHERE mem_first_name = %s OR mem_last_name = %s"

Open in new window

Comment
Watch Question

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
that kind of query should actually work.
so, the question is:
what error do you get, actually?
how exactly do you fill in the search string into %s ?

Author

Commented:
I thought it would to.  I did it a different way and it worked as well.
Thanks for you help.
"SELECT * FROM members WHERE mem_first_name = '$search_name' OR mem_last_name = '$search_name'";

Explore More ContentExplore courses, solutions, and other research materials related to this topic.