Union Two Tables And TimeStampDiff?

This union works fine except when I include TimeStampDiff. I receive the following error:

          "Unknown column 'colDateTime' in 'having clause' "

Select col1
From
(
Select col1 From table1
Union All
Select col2 From table1
)
as tmp
Group By col1
Having TimeStampDiff(Hour, Max(colDateTime), Now()) <= '24'

Note: Also tried "table1.colDateTime", but still same error...
pointemanAsked:
Who is Participating?
 
Kevin CrossConnect With a Mentor Chief Technology OfficerCommented:
You will need to include the colDateTime in the SELECT for each of the union member queries or add the timestampdiff to select queris.
Select col1
From 
(
Select col1, colDateTime From table1
Union All
Select col2 AS col1, colx AS colDateTime From table1 
)
as tmp
Group By col1
Having TimeStampDiff(Hour, Max(colDateTime), Now()) <= 24

Open in new window

0
 
pointemanAuthor Commented:
Why didn't I think of that?

Thank you....
0
 
Kevin CrossChief Technology OfficerCommented:
You are welcome!

Glad that helped.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.