vulkan vulkan - 4 months ago 6
SQL Question

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
*I using PHP

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);
}

Answer

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%';