Solved

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

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

622 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