Home > Software engineering >  Filter SQL query where one column is a json
Filter SQL query where one column is a json

Time:06-28

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"?

CodePudding user response:

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.

  • Related