0

please help mi relating to following mysql query, I have a table main with like below:

id      phone                phone2 
======================================
1       98998 | 58877
2       98998 | 58877
3       98998

i want to update phone2 through phone column and trying to used following subquery but i didnt got the desired result please help to got the result if it is possible:

update main a 
set a.phone2 = (SELECT substring_index(b.phone,'|',-1) 
                FROM main b 
where b.phone like '%|%' and where a.id=b.id) 
4

1 に答える 1

1

これを試して:

UPDATE main a 
    INNER JOIN (SELECT id, substring_index(phone,'|',-1) AS phone
                FROM main 
                WHERE phone LIKE '%|%' 
        ) b
        ON a.id = b.id
SET a.phone2 = b.phone;
于 2012-08-06T11:15:13.427 に答える