A
A
Alexander Ivanov2014-09-06 10:53:54
PHP
Alexander Ivanov, 2014-09-06 10:53:54

How to do multi-column search in SQL?

There is a field (input type="search" name="search"). I have a table with five columns.
How to find an entry, for example, in the second column and in the third?
Tried like this:

Select * from `table` where `colum3` & `column2` Like '%$search%'

Gives out zero.
Option 2
Select * from `table` where `colum3` AND `column2` Like '%$search%'

This code works, but for some reason it doesn't find the number!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ivanov, 2014-09-06
@cimonlebedev

Got it right:

Select * from `table` where `colum3`  Like '%$search%' OR `column2` Like '%$search%'

A
Alexander Zelenin, 2014-09-06
@zelenin

select * from table where column2 = $search
union
select * from table where column3 = $search

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question