Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:17:47+00:00 2026-06-09T14:17:47+00:00

I have combined two tables using union all . However, the produced data has

  • 0

I have combined two tables using union all. However, the produced data has repeats. Is there a way to join the repeats?

For example, the resulting table after union all, t, looks like this”:

__DAY__.....................__COUNT__
monday....................1
tuesday...................2
tuesday...................3
wednesday..............4
wednesday..............1
wednesday..............5

I would like it to look like this:

__DAY__.................__COUNT__
monday....................1
tuesday....................5
wednesday..............10

Also, I tried “group by t.day, t.count” and it does not work.
And the “….” are for formatting purposes only, in order to have some sort of indent.

The query is the following.

SELECT   t1.hour, t1.day, t1.count
FROM
(
  (SELECT hour(time(FROM_UNIXTIME( timecode)))  AS hour,
   date(FROM_UNIXTIME( timecode))  AS day,
  (FROM_UNIXTIME( timecode)) AS original, COUNT(1)  as 'count'
   FROM sampleData
  WHERE hour(time(FROM_UNIXTIME( timecode)))>=14
   GROUP BY DAY)
 union all
  (SELECT hour(time(FROM_UNIXTIME( timecode))) as hour,
   date(FROM_UNIXTIME( timecode-86400) ) AS day,
   (FROM_UNIXTIME( timecode)) AS original, COUNT(1)  as 'count'
  FROM sampleData
  WHERE hour(time(FROM_UNIXTIME( timecode)))< 14
   GROUP BY DAY)
)  t1
GROUP BY  t1.day, t1.count
HAVING COUNT(*)>0
ORDER BY t1.day
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:17:49+00:00Added an answer on June 9, 2026 at 2:17 pm

    Try this simple query:

    SELECT day,sum(count) FROM Table1
    Group by day
    

    See this SQLFiddle

    EDIT: For your query try this:

    SELECT   t1.hour, t1.day, sum(t1.count)
    FROM 
    (
      (SELECT hour(time(FROM_UNIXTIME( timecode)))  AS hour,  
       date(FROM_UNIXTIME( timecode))  AS day, 
      (FROM_UNIXTIME( timecode)) AS original, COUNT(1)  as 'count'  
       FROM sampleData  
      WHERE hour(time(FROM_UNIXTIME( timecode)))>=14  
       GROUP BY DAY)   
     union all   
      (SELECT hour(time(FROM_UNIXTIME( timecode))) as hour,  
       date(FROM_UNIXTIME( timecode-86400) ) AS day,  
       (FROM_UNIXTIME( timecode)) AS original, COUNT(1)  as 'count'  
      FROM sampleData   
      WHERE hour(time(FROM_UNIXTIME( timecode)))< 14  
       GROUP BY DAY)  
    )  t1  
    GROUP BY  t1.day
    HAVING COUNT(*)>0  
    ORDER BY t1.day  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view which combines two tables using UNION ALL . Is it
I have a scenario where I combine two tables into one (using UNION) and
I am using devbridge jquery autocomplete plugin . I have combined two tables in
i have two queries being combined with a UNION ALL 1 : --Query 1
I have two tables Table1 and Table2. There are 10 fields in Table1 and
I have two tables, items and itemmeta. items has item_id which links it to
I am using SQL Server and I have two tables and I would like
I have two tables, Book and Tag , and books are tagged using the
I have two tables of data categories and category relations. This is a setup
Is there a best practice in getting data from multiple database tables using Zend?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.