I have two different table artifact and classification. I want to retrieve list of artifacts who dont have classification. The classification table contains ID(PK), Artifact_Id(foreign key), Active(0/1) while the artifact table contains ID(PK),Name. Each artifact can have many classification. I want to return a list of artifacts when there is no classification for it (i.e. classification does not contain that artifact or when the artifact has classification but all of instances are not active(0))
For example
Artifact
Id Name
1 xyz
2 pqr
3 abc
Classification
Id Artifact_id active
a1 1 0
a2 1 0
a3 1 0
a4 3 0
a5 3 1
In the above case the artifact 1 and 2 has no classification but 3 has classification since one instance is active(1). So I want to return 1 and 2. I am not sure how to query this. This is what I have tried (not too much though and is wrong)
def list = findAll("from artifact as a full outer join classification as c on a.id=c.artifact_id where active == 0 OR c.aritfact_id is NULL,[max:limit, offset:startPos])
I also tried something in sql
select * from ARTIFACT full outer join classification on artifact.id = classification.ARTIFACT_ID where sum(classification.active) == 0 OR classification.aritfact_id is NULL