Solved

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

Posted on 2013-06-09
2
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 41

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

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 …
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…

752 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