选择UID但不选择具有给定状态的UID?

enter image description hereI am programming a simple Customer Database (Bridal Gowns) for my own business and try to reach the following goal:

I try to filter out those uids which do not have an "ordered = 1" flag. So, all the entries from a user, where at least one entry has an "ordered = 1" flag should not be shown.

In the picture below, all entries for user 575 should not be shown as he has already ordered one dress...

Can this be done?

Kind Regards,

Stefan

Use not exists

select a1.*
from MyTable a1
where not exists (select 1  
                  from MyTable a2
                  where ordered = 1
                  and a1.UID = a2.UID)

You can also use NOT IN

SELECT
 *
FROM 
 [table]
WHERE 
 uid NOT IN ( 
  SELECT 
   uid
  FROM 
   [table]
  WHERE
   ordered = 1   
 ) 
        select *
from wccrm_kunden
where not exists (select 1  
                  from wccrm_anprobe
                  where ordered = 1
                  and wccrm_kunden.id = wccrm_anprobe.uid)
group by wccrm_kunden.id