1
{
  "people": {
    "Man": {
      "Employee": "50",
      "Student": "91",
      "Artist": "80",
      "Clark": "50"
    },
    "Woman": {
      "Employee": "21",
      "Student": "01",
      "Artist": "00",
      "k3": "30",
      "Clark": "68"
    }
  }
}

How can I Update Employee Value From Man Object. I want something similar to below mysql query.

UPDATE TABLE 
   SET Column = JSON_SET(Column, '$.people.Man.Employee', '51') 
  WHERE Id=1234567890;

MariaDB [**********]> SELECT VERSION();

+--------------------------------------------+
| VERSION()                                  |
+--------------------------------------------+
| 10.3.17-MariaDB-1:10.3.17+maria~bionic-log |
+--------------------------------------------+

2 Answers 2

1

Firstly, fix the keys within the JSON column by adding quotes for each, and values by adding quotes for some which starts with zeroes and go on with other digits.

Then apply :

UPDATE tab
   SET Col = JSON_SET(
       Col,
       "$.people.Man.Employee", "50",
       "$.people.Man.Employee", "51"
       )
 WHERE ID = 1234567890;

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thank You Very Much. This is perfectly Worked.
0

Even, I don't see any problem with the following

UPDATE tab
SET 
    Col = JSON_SET(Col, '$.people.Man.Employee', '51')
WHERE
    Id = 1234567890;

Demo

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.