WmZilla - Webmaster and Marketplace

The Next Generation Webmaster and Trade Forum

Help! Retrieve only non-null columns in MYSQL!

Deu

New member

0

0%

Status

Offline

Posts

30

Likes

0

Rep

0

Bits

160

3

Months of Service

0%
Hello friends, for the past 2 days, I have been stuck on an issue in MYSQL that I haven't been able to solve, so I'm asking for help from friends who are knowledgeable in MYSQL. In my Mysql table, I have a column named "value" that contains JSON codes. To explain more easily, I will enter 3 sample data below:

--------------------------------------------------
id | u_id | value |
==============================================
1 | 3 | {"23": ["0", "1", "2", "3"], "25": ["1", "2", "0"]}
--------------------------------------------------
2 | 4 | {"49": ["1"], "52": ["0", "1"], "53": ["2"], "54": ["0"]}
--------------------------------------------------
3 | 2 | {"25": ["1"], "52": ["0", "1"], "53": ["2"], "54": ["0"]}
--------------------------------------------------

SQL Query I ran:

SELECT id, u_id, JSON_SEARCH(value->'$."23"','one','1') as `23`, JSON_SEARCH(value->'$."49"','one','1') as `49` FROM table_name

SQL Query Result:

___________________________________
id | u_id | 23 | 49 |
===========================
1 | 3 | "$[1]" | NULL |
--------------------------------------------------
2 | 4 | NULL | "$[0]" |
--------------------------------------------------
3 | 2 | NULL | NULL |
--------------------------------------------------

The desired results I want to find within the JSON are in columns 23 and 49. Now, I want to hide the table that does not have the 3rd ID in it, which is where both columns 23 and 49 are not NULL, and retrieve the u_id values of the remaining results.

The purpose is as follows: Are there values in both columns 23 and 49? If yes:
Retrieve the IDs that do not have NULL values in both columns. (So, IDs 1 and 2)

If there are no values in either column 23 or 49:
Do not return any results.

When I run HAVING `23`IS NOT NULL or `49` IS NOT NULL command, I noticed that it fetches the non-empty value when one of them is empty. However, what I want is not to return any value when one of them is empty. Then, when I run HAVING `23`IS NOT NULL and `49` IS NOT NULL command, it doesn't return any result.

I hope I have been able to explain well. I urgently need to solve this issue for the progress of my project. I really need your help. Thank you.
 

249

6,622

6,642

Top