Mohammad Mohammad - 5 months ago 11
SQL Question

PHP+MySql : select row by like ( with and without space )


My table :


Mohammad
Ali
Moham mad
m Ohammad
Reza
Nasser
Mohamma d


I want select from this table and return all name of mohammad even use space or not use space


Like :


select * from table where name like '%mohammad%' // i want return Mohammad,Moham mad,m Ohammad,Mohamma d



Also :


select * from table where name like '%Mohamma d%' // i want return Mohammad,Moham mad,m Ohammad,Mohamma d



And :


select * from table where name like '%Moham mad%' // i want return Mohammad,Moham mad,m Ohammad,Mohamma d

Answer
select * from table where REPLACE(name,' ','') like '%mohammad%'
Comments