Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter SQL query where one column is a json

I have a column in SQL that has a JSON formatted data inside of it. For example, lets call this column JSON and the first input would be

{
  "ID" :123, 
  "NAME": NULL, 
  "FINISH": "MATTE"
}

How can I filter this column and only display values that don’t have a NULL input in a variable such as "NAME"?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’d go with the following approach:

select *
from <your_table>
where json_value(<your_json_column>, '$.name') is not null;

In the query above, you’d only need to change <your_table> for the actual name of the table, and <your_json_column> for the actual name of the JSON column.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading