MattBlack MattBlack - 1 year ago 99
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?


Answer Source

You should use CONCAT :

UPDATE staff
SET deductions='$row[15]', $phonepayment = '$row[16]'
WHERE CONCAT(firstname, ' ', lastaname) = $row[1]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download