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) 
1
  • It seems that you have two numbers in coloumn phone seperated by "|". Are you trying to seperate two numbers, keeping one in phone and other in phone2. Editing with sample/example will help in understanding question. Commented Aug 6, 2012 at 11:17

1 Answer 1

1

try this:

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.