Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

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...
0
pointeman
Asked:
pointeman
  • 2
1 Solution
 
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
 
pointemanAuthor Commented:
Why didn't I think of that?

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

Glad that helped.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now