Solved

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

Posted on 2013-06-09
2
391 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Transferring database from one server to another 1 64
MySQL - search xml field for multiple occurrences of specific text 6 51
Database Design Concept 3 51
Trigger usage 2 59
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

16 Experts available now in Live!

Get 1:1 Help Now