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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin CrossChief 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pointemanAuthor Commented:
Why didn't I think of that?

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

Glad that helped.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.