Hi, I have these config in postgre:
Tables
DEF
NAMEJOB
ID_JOB
ID_TABLE
....
VARIABLE
ID_JOB
ID_TABLE
NAME
VALUE
....
Registers examples:
DEF
NAMEJOB="APPLE"
ID_JOB=1
ID_TABLE=1
NAMEJOB="HOUSE"
ID_JOB=2
ID_TABLE=2
VARIABLE
ID_JOB=1
ID_TABLE=1
NAME="COLOR"
VALUE="GREEN"
ID_JOB=1
ID_TABLE=1
NAME="SIZE"
VALUE="SMALL"
ID_JOB=2
ID_TABLE=2
NAME="COLOR"
VALUE="BROWN"
......
I would like to get all registers that don't have "NAME=SIZE" IN THE TABLE VARIABLE. So the output should be:
ID_JOB=2
ID_TABLE=2
NAMEJOB=HOUSE
If I make a where with job_id and table_id shows me all registers. Someone could help me please? Thanks and sorry for my English!
I wanted to post only SQL, but can't, have to make it look like a "sentence" because of this site's damn parser:
SELECT VARS.ID_JOB, VARS.ID_TABLE, VARS.NAMEJOB
FROM (
SELECT ID_JOB, ID_TABLE
FROM [VARIABLE]
GROUP BY ID_JOB, ID_TABLE
HAVING MAX(CASE WHEN NAME = 'SIZE' THEN 1 ELSE 0 END) = 0
) AS VARS
INNER JOIN DEF ON DEF.ID_JOB = VARS.ID_JOB AND DEF.ID_TABLE = VARS.ID_TABLE
1 Like
Thanks it's a good approximation.
Gives me more registers than expected.
But I'm culprit.
I forget mention that in DEF TABLE there is other column (called TYPE) where I must obtain all of TYPE=C. Because in VARIABLE there are a lot or register and not all are of the type C.
If I use your query gives me all types and not only of type C.
Thanks and sorry for my English!