简体   繁体   中英

SQL Select query where column like string with and without spaces

I have a SQL Select query in PHP where i need to lookup rows in a table where a column is like a string with and without spaces

for example, if my value in the database is ABC 123 and i search for ABC123 the query will be

$sql = SELECT * from table where col_name LIKE '%ABC123%' ";

but i need it to return the row where col_name equals ABC 123

and vice versa, for example, if the database value is 123ABC and i search for 123 ABC the query will be

$sql = SELECT * from table where col_name LIKE '%123 ABC%' ";

and i need it to return the row where col_name equals 123ABC

$sql = SELECT * from table where REPLACE(col_name,' ','') LIKE '%ABC123%' ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM