简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM