Gisheri
Gisheri

Reputation: 1715

Why doesn't this query work? Combining Having and Where

SELECT fileUser FROM `images` 
HAVING min(imageid) AND 
WHERE (finished=0 and processing=0)

It seems a simple thing to get the fileUser index with the least imageID where finished and processing also = 0. But, I cannot seem to come up with a query that works? Any help would be great.

Upvotes: 1

Views: 80

Answers (3)

Himanshu
Himanshu

Reputation: 32622

If you question is related to your previous question, then you can try this one:

SELECT fileUser FROM `images`
WHERE imageid = (SELECT min(imageid) 
                 FROM `images` 
                WHERE finished=0 
                  AND processing=0)

See this SQLFiddle Demo

Upvotes: 2

Mr. 14
Mr. 14

Reputation: 9528

An alternative way would be

SELECT fileUser 
FROM `images` 
WHERE finished=0 
AND processing=0
ORDER BY imageid
LIMIT 1

Upvotes: 1

Carth
Carth

Reputation: 2343

I think he actually wants this

SELECT fileUser FROM `images`
WHERE imageid = (SELECT min(imageid) FROM `images` WHERE (finished=0 and processing=0))

Upvotes: 0

Related Questions