How to understand CONCAT

if ( $nickname != "" ) {
  $where .= " and CONCAT(a.nickname,a.mobile, a.card_number) like "%" . $nickname . "%"";
}

and

$where .= "and (a.nickname like "%{$nickname}%" or a.mobile like "%{$nickname}%" or a.card_number like "%{$nickname}%")";
The effect of

is the same. Obviously, the above method of writing is much simpler

.
Mar.10,2022
The

string function, which is simple to understand, is to concatenate multiple strings together.
and concat_ws,group_concat, look up the information and it will be clear at a glance.


in principle, the resource consumption of LIKE%% should have been avoided, let alone in the case of multiple fields.

if multiple fields of a result set are queried, it is equivalent to traversing a collection multiple times,

but if you use concat, you merge multiple columns together and then you only need to query it once. However, if the field content of the concat is relatively long, it is still recommended to separate that field and or it. It doesn't matter if it's all a small amount of data.

the first way is to judge NULL, otherwise if there is a column of NULL in mysql, then that line will become NULL and cause unexpected results.

   

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e64b28-6746e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e64b28-6746e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?