Get reference to master select row in nested select
I want my DB to return row under one of two conditions:
The row contains specific value "val" and is of type "sometype"
There is other row, that does have the type "sometype" and the same name
as currently checked row.
For this purpose, I made a folowing query:
SELECT c.name, c.value, c.type
FROM `table` AS c
WHERE
c.type='sometype' AND c.value='val'
OR
c.type='othertype' AND
0<(SELECT count(*) FROM `table` AS d WHERE d.name=c.name and
c.name='sometype')
Unfortunately, this will return all rows of 'othertype'. I only want
these, that have friend with same name and type 'sometype'.
I think the problem is, that I don't know how to get the reference to the
values in curently checked row (which I believed to be c.fieldname). I
believed d.name = c.name would return all rows that have same name as
currently checked row. But the nested select is always >0.
No comments:
Post a Comment