在where中连接两列


Concatenate two columns in where

我有一个变量,它包含一个全名和一个表,其中的名字分为名和姓。

我正在尝试更新记录,其中名字与姓氏连接等于变量。

$row[1]="Joe Bloggs"
$sql = "UPDATE staff SET deductions='$row[15]', $phonepayment = '$row[16]' WHERE firstname.' '.lastaname= $row[1]";

我该怎么做呢?

你应该使用CONCAT:

UPDATE staff
SET deductions='$row[15]', $phonepayment = '$row[16]'
WHERE CONCAT(firstname, ' ', lastaname) = $row[1]

尝试下面的查询,您可以使用+运算符组合字符串。

   $row[1]="Joe Bloggs"
     $sql = "UPDATE staff 
                 SET deductions='$row[15]', $phonepayment = '$row[16]' 
                 WHERE firstname+' '+lastaname= $row[1]";

在WHERE子句中使用:

WHERE firstname + ' ' + lastname = $row[1]