if all subrecords is=* then show me records from main one. (1 Viewer)

TipsyWolf

Member
Local time
Today, 18:06
Joined
Mar 20, 2024
Messages
211
hey guys,
i can't figure it out how to set a criteria for subtable if all related records will be with lets say status "completed"
2 example:

main table:
ID ------Isactive
1 --------true

sub table
ID--------status
1 ---- in progress
2 ---- completed

main table:
ID -----Isactive
2 ----- true

sub table
ID ------ status
3 ------completed
4 ------completed
5 ------completed

i need to get all records from main table where isactive= true (its simple), but as well as all record related to main table in this case ID2 have 3 out of 3 records from sub table with 100% completion. while ID1 has1 sub records with status "in progress'

picture will explain much better

1719427580860.png
 

TipsyWolf

Member
Local time
Today, 18:06
Joined
Mar 20, 2024
Messages
211
In the criteria, just try entering "completed"
yeah, but it shows ID2 three times ... but i need only 1

1719428079950.png


but what if RISK 2 has some subrecord with different status ?
i wont be able see in this case

i need to check like
IF every (100%) records are completed then show me the ID from main table.

so simple put it

main table - RISK table
sub table = Actions table. an actions need to perform in order to close RISK.

so i need to see if all actions have been performed. sometimes its 1 action , sometimes its 10 records.
 

TipsyWolf

Member
Local time
Today, 18:06
Joined
Mar 20, 2024
Messages
211
In the criteria, just try entering "completed"
look

ID2
1719428730132.png

it doesnt fit to my criteris, as 1 sub records has in progress status.

i need to check if all subrecords "completed" in this case there are 4 records and its 3 out of 4 or 75%. completion
and if they are all = "completed" then give me ID from main table ... then i can do the rest ))

IF sub record ID 920 status would be = completed , then i want to see RiskID 2 in my queiry
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:06
Joined
Feb 19, 2013
Messages
16,775
Two queries

first one
Select distinct riskid from Tactions where status <>’completed’

second one

select tmain.* from tmain left join firstquery on main.riskid =firstquery.riskid where firstquery.riskid is null
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:06
Joined
Sep 21, 2011
Messages
14,713
Why are you trying to redact status? If you click on image to see it better they are are redacted?
How on earth is that confidential? :(

Fortunately they are visible on a PC without having to click on the image, not so great on a phone. :(
 

TipsyWolf

Member
Local time
Today, 18:06
Joined
Mar 20, 2024
Messages
211
If you click on image to see it better they are are redacted
didn't know it acts like it. its weird. just took paint to do it fast.
and its more about remove info that are not necessary in our case so ppl can read easily lol . this is absolutely non-confidential info.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:06
Joined
May 21, 2018
Messages
8,748
This worked for me.
Code:
SELECT tmain.riskid,
       tmain.isactive,
       "All Actions Complete" AS AllComplete
FROM   tmain
WHERE  tmain.isactive = true
         AND EXISTS (SELECT *
                         FROM   tactions
                         WHERE  tactions.riskid = tmain.riskid
                                AND tactions.status <> "completed") = false
 

TipsyWolf

Member
Local time
Today, 18:06
Joined
Mar 20, 2024
Messages
211
This worked for me.
Code:
SELECT tmain.riskid,
       tmain.isactive,
       "All Actions Complete" AS AllComplete
FROM   tmain
WHERE  tmain.isactive = true
         AND EXISTS (SELECT *
                         FROM   tactions
                         WHERE  tactions.riskid = tmain.riskid
                                AND tactions.status <> "completed") = false
u prob. will laugh at me , but looks like i set it up wrongly

1719430243130.png


1719430272021.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:06
Joined
May 21, 2018
Messages
8,748
You left in a comma before the "From" after isactive. I added a literal string that you took out.
 

TipsyWolf

Member
Local time
Today, 18:06
Joined
Mar 20, 2024
Messages
211
This worked for me.
Code:
SELECT tmain.riskid,
       tmain.isactive,
       "All Actions Complete" AS AllComplete
FROM   tmain
WHERE  tmain.isactive = true
         AND EXISTS (SELECT *
                         FROM   tactions
                         WHERE  tactions.riskid = tmain.riskid
                                AND tactions.status <> "completed") = false
1719431714826.png


ID6 = all completed !
1719431846510.png


@MajP - thank u very much ! helped me a lot !
 

Users who are viewing this thread

Top Bottom