Hi!! I'm having a problem. I'm trying to do a query... I remember that in the past I did something like this but today this query is returning nothing, no error, no data, just nothing... the query is something like this:
SELECT field1, @variableX:=field2
FROM table
WHERE
(SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=0)>0 AND
(SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=4)=0;
I also tried this query but it didn't work (also it gaves no error):
SELECT field1, @variableX:=field2,
@variableY:=(SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=0),
@variableZ:=(SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=4)
FROM table
WHERE @variableY>0 AND @variableZ=0;
As you can see, what I'm trying to do in the 1st query is use a variable in the conditions. In the 2nd query I'm trying to create some variables and evaluate them in the conditions. At the end in the 2nd query the @variableY=1 AND @variableZ=0 but I don't know why the query returns an empty data set.
What could be wrong here??? Any comment or suggestion is welcome!!! Thanks!!! Bye!!!