Solved

Select from many tables, same columns but in own table for each month

Posted on 2013-06-09
2
376 Views
Last Modified: 2013-06-09
Hello,

I have 12 tables, one for each month. Each table has the same structure just a different name. What would be the best way to join these to select all data (in this case where w has a value) to show ordered by date.

I also need to select a name from a user table that matches the userid stored in the monthly table.

This is what I use if just selecting from the one table.

SELECT name,`thedate`,`vmtd`,`w`, `c`FROM `2013_ws_January` j, tbl_users u where uid=u.id and `w` !='' order by uid, `thedate`;

Open in new window


Each table for the monthly data is made up of `id`,`uid`,`thedate`,`vmtd`,`w`,`c`
Tables name example 2013_ws_January, 2013_ws_February etc.

Thanks for reading.
0
Comment
Question by:AUCKLANDIT
2 Comments
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 39233275
SELECT name,thedate,vmtd,w,c
 FROM (
 SELECT * FROM ``2013_ws_January` UNION ALL
 SELECT * FROM `2013_ws_February` UNION ALL
 SELECT * FROM `2013_ws_March` UNION ALL
 SELECT * FROM `2013_ws_April` UNION ALL
 SELECT * FROM `2013_ws_May` UNION ALL
 SELECT * FROM `2013_ws_June` UNION ALL
 SELECT * FROM `2013_ws_July` UNION ALL
 SELECT * FROM `2013_ws_August` UNION ALL
 SELECT * FROM `2013_ws_September` UNION ALL
 SELECT * FROM `2013_ws_October` UNION ALL
 SELECT * FROM `2013_ws_November` UNION ALL
 SELECT * FROM `2013_ws_December`) as j innner join tbl_users u on  uid=u.id and w !=''
0
 
LVL 1

Author Closing Comment

by:AUCKLANDIT
ID: 39233738
Spot on thank you.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now