0

I have an SQL Table which one of the columns contain a JSON array in the following format:

[  
   {  
      "id":"1",
      "translation":"something here",
      "value":"value of something here"
   },
   {  
      "id":"2",
      "translation":"something else here",
      "value":"value of something else here"
   },
..
..
..
]

Is there any way to use an SQL Query and retrieve columns with the ID as header and the "value" as the value of the column? Instead of return only one column with the JSON array.

For example, if I run:

SELECT column_with_json FROM myTable

It will return the above array. Where I want to return

1,2
value of something here, value of something else here

1 Answer 1

0

You can't use SQL to retrieve columns from the JSON stored inside the table: to the database engine the JSON is just unstructured text saved in a text field.

Some relational databases, like PostgreSQL, have a JSON type and functions to support JSON query. If this is your case, you should be able to perform the query you want.

Check this for an example on how it work with PostgreSQL: http://clarkdave.net/2013/06/what-can-you-do-with-postgresql-and-json/

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

2 Comments

It is a mySQL from PHPmyADMIN in wordpress. I use a Wordpress plugin (MiwoSQL) to run SQL Queries from dashboard. Instead of doing this, will I have the option to do what I want if I use a PHP code to retrieve the files from SQL table?
Yes, you can retrieve the text using SQL and use PHP to parse the JSON to an array: stackoverflow.com/questions/11051711/parsing-sql-query-php

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.