mysql - Get reference to master select row in nested select -


i want db return row under 1 of 2 conditions:

  1. the row contains specific value "val" , of type "sometype"
  2. there other row, have type "sometype" , same name checked row.

for purpose, made folowing query:

select c.name, c.value, c.type    `table` c          c.type='sometype' , c.value='val'        or        c.type='othertype' ,           0<(select count(*) `table` d d.name=c.name , c.name='sometype') 

unfortunately, return rows of 'othertype'. want these, have friend same name , type 'sometype'.
think problem is, don't know how reference values in curently checked row (which believed c.fieldname). believed d.name = c.name return rows have same name checked row. nested select >0.

i think should work doing:

select c.name, c.type, c.value test c inner join (select name, type             test             type = "type1"             , value = 3) d on c.name = d.name , c.type = d.type; 

sqlfiddle: http://sqlfiddle.com/#!2/63255/1

the inner select gets #1, type="sometype" , value="val". outer gets names, types , values correspond name , type of inner select, #2.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -