我与AS合并了两列,现在我想用LIKE搜索其中的数据。我怎样才能做到这一点?以下是我到目前为止的尝试。
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);
}
答案 0 :(得分:2)
我认为你可以尝试这样 - 使用having
子句而不是
select concat( field1, field2 ) as 'alias'
from `table`
having `alias` like '%word%'
或者,在您的情况下:
SELECT CONCAT (`name` , ' ' , `surname`) AS 'full' FROM `person`
having `full` like '%word%';
答案 1 :(得分:0)
使用子查询。
子查询"SELECT CONCAT (name , ' ' , surname) AS full FROM person "
完成查询:
SELECT * from (SELECT CONCAT (name , ' ' , surname) AS full FROM person) where
full like '%a%';
希望它会有所帮助。
答案 2 :(得分:0)
您也可以尝试
SELECT *
FROM pages
WHERE CONCAT_WS('', column1, column2, column3) LIKE '%keyword%'