MattBlack MattBlack - 2 months ago 10
SQL Question

Concatenate two columns in where

I have a variable which contains a full name and a table which has the names separated into first name and last name.

I am trying to update records where the first name joined with the last name equals the variable.



$row[1]="Joe Bloggs"

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





How would I go about achieving this?

Thanks!

Answer

You should use CONCAT :

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