Fall in IT.

MySQL JSON 데이터 필드 조회하는 방법 본문

데이터베이스/MySQL

MySQL JSON 데이터 필드 조회하는 방법

D.Y 2020. 7. 7. 16:47

문제

User Table에 agreement 필드가 있고,

agreement 필드의 값으로 JSON DATA가 저장되어 있을 경우 JSON DATA의 특정 값을 조회하고 싶다.

 

방법

# 마케팅 알람설정값 모두 조회	
SELECT JSON_EXTRACT(agreement, '$.MarketingAlarm') as MarketingAlarm
	FROM user
    
# 마케팅 알람설정이 true인 데이터만 조회
SELECT JSON_EXTRACT(agreement, '$.MarketingAlarm') as MarketingAlarm
	FROM user
	WHERE JSON_EXTRACT(agreement, '$.MarketingAlarm') = true

 

 

 

 

 

 

'데이터베이스 > MySQL' 카테고리의 다른 글

A Table에서 B Table로 데이터 옮기는 방법  (0) 2019.07.23
Comments