mysql - Filtering select with join on the same table -


let's got table named entity has following columns:
id | flag | foreignkey | parententityid

misc notes

  • none of fields can null
  • when parententityid !=0 can sure foreignkey has value !=0 (and vice-versa)

i had gather data following constraints :

  • foreignkey has equal 0 [easy :d]
  • flag must equal 0 or (let's 15) [easy :p]
  • id must not referenced on row's parententityid field [ :/ ?]

i did not manage satisfy last constraint using self join

-- ended sub-query (which returns need) : select e.* entity e e.flag='15'  -- gathering entities ids foreignkey has specific value  , e.id not in   (select group_concat(distinct convert(parentid , char(8)) separator ",")      entity foreignkey='10'      group id   ); 

my question .. can achieved "self join" expression ?

something (for conditions in text):

select e.* entity e e.foreignkey = 0 ,       e.flag in (0, 15) ,       not exists (select 1 entity e2 e2.parentid = e.id); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -