0

Well, I've got a subquery that contains an "having" condition. So I have to add the parameters in the having condition in the select clause, right?

So I've got the subquery:

SELECT sfd.id, sfd.StartTime, sfd.EndTime, sd.StartTime 
FROM ssp.SessionFloatData sfd, ssp.SessionData_daily sd 
WHERE Name = 'nsrserverhost' AND Parameter = 'storagenode' 
AND sd.id = sfd.id 
HAVING (sfd.StartTime <= sd.StartTime AND sfd.EndTime >= sd.StartTime)

but in fact I'm only interested in the the first column: I just want to retrieve the id.

The excerpt of my whole statement is

WHERE sfd.id IN (SELECT sfd.id, sfd.StartTime, sfd.EndTime, sd.StartTime 
...
                HAVING (sfd.StartTime <= sd.StartTime AND sfd.EndTime >= sd.StartTime))

What obiously fails as four columns are returned :( What can I do?

Update: Selecting just sfd.id results in an error: ERROR 1054 (42S22): Unknown column 'sfd.StartTime' in 'having clause' Changing the 'having'

Christian Graf
  • 406
  • 2
  • 10
  • 26
  • 1
    Have you tried removing the other columns? Also, are you missing a `GROUP BY` clause? If not, remove the `HAVING` statement and include with `WHERE`. – sgeddes Mar 28 '14 at 14:23

1 Answers1

1

I don't understand what you try to do. The HAVING clause is only used when in conjuction with GROUP BY clause. In your case I suposse you could do this:

SELECT sfd.id
FROM ssp.SessionFloatData sfd, ssp.SessionData_daily sd 
WHERE Name = 'nsrserverhost' AND Parameter = 'storagenode' 
AND sfd.StartTime <= sd.StartTime AND sfd.EndTime >= sd.StartTime
AND sd.id = sfd.id 
GROUP BY sfd.id

So what was on HAVING is passed to WHERE clause. Is this what you want?

ericpap
  • 2,917
  • 5
  • 33
  • 52