简体   繁体   中英

How to search with LIKE in columns merged with AS

I merged two column with AS , now I want to search data inside them with LIKE. How can i do that? Here is what I have tries so far.

Php :

$sql = "SELECT CONCAT (name , ' ' , surname) AS full  FROM person ";
$query = mysqli_query($con,$sql);
if($query){
    while($row=mysqli_fetch_assoc($query)){
        echo "<p>$row[full]</p>";
    }
}else{
    echo mysqli_error($con);
}

I think you could try like this - using the having clause rather than where

select concat( field1, field2 ) as 'alias'
from `table`
having `alias` like '%word%'

or, in your case:

SELECT CONCAT (`name` , ' ' , `surname`) AS 'full'  FROM `person`
having `full` like '%word%';

Use subquery.

Subquery "SELECT CONCAT (name , ' ' , surname) AS full FROM person "

Complete Query :

SELECT * from (SELECT CONCAT (name , ' ' , surname) AS full  FROM person) where 
full like '%a%';

Hope it will help.

You can try also

SELECT * 
FROM pages 
WHERE CONCAT_WS('', column1, column2, column3) LIKE '%keyword%'

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