I have a "users" table in my database, unfortunately there is a lot of mess in it and I try to move it to new one. But just exact things not copy / paste whole.
Here is example how db looks like:
-------*/*------------*/*------------*/*------------*/*------------*/*------------
id level name kind status parentId
-------*/*------------*/*------------*/*------------*/*----------*/*------------
EMD123F | 2 | OrgName1 | Org | | rootID
---------------------------------------------------------------------------------
DHAD781 | 3 | UserName1 | Person | active | EMD123F
---------------------------------------------------------------------------------
7AJIZU7 | 3 | UserName2 | Person | active | EMD123F
---------------------------------------------------------------------------------
DME123F | 2 | OrgName2 | Org | | rootID
---------------------------------------------------------------------------------
TT5451AL| 3 | UserName3 | Person | active | DME123F
---------------------------------------------------------------------------------
RRMI7481| 2 | OrgName3 | Org | | rootID
---------------------------------------------------------------------------------
PPUNSAD9| 2 | OrgName4 | Org | | rootID
---------------------------------------------------------------------------------
GJASDNZB| 3 | UserName4 | Person | inactive | PPUNSAD9
---------------------------------------------------------------------------------
KJNSCZM7| 2 | OrgName5 | Org | | rootID
---------------------------------------------------------------------------------
1UZGOPAS| 3 | UserName5 | Person | deleted | KJNSCZM7
---------------------------------------------------------------------------------
What you see here that there are some "Organizations" which have 0 users so are absolutley useless, there are some organizations which have users but they are not active ( inactive , deleted... ).
My question is how to write a select statement to get ALL ORGANIZATION WHERE there is atelast 1 active person inside of it.
RealData is a bit more complicated but I try something like this:
UPDATE users set org_status=1 WHERE (select count(STATUS) FROM users WHERE users.MEMBERKIND="Person" AND users.STATUS="Active" AND users.ROOTORGANIZATIONUSERID= users.ROOTORGANIZATIONIDCORRECTED)>0 AND MEMBERKIND = "Organization" AND LEVEL=2
I create new row "org_status" and set it to NULL and after that I try to update it