First of all I'm using mysql 5.6
I want to select all the elements that satisfy at least one of these request:
- Do not have a certain field.
- A certain field has an empty value (for empty I mean:
len(trim(value)) == 0
)
I'll make an example to be more clear
table2
id|field|value
1 |x |12
1 |y |23
1 |z |34
2 |x |45
2 |y |56
2 |z | <---- is an empty string with 0/1 spaces
3 |x |67
So what I want is for example if I want all field that do not have field z
I should obtain (2,3
)
In case of all fields without y
I should obtain (3
)
This is what I tried without much success:
SELECT t12.id
FROM table2 AS t12
WHERE NOT IN (
SELECT t2.id
FROM table2 as t2
WHERE t2.field = 'y'
AND t2.value <> '' AND t2.value IS NOT NULL
)