Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-09
2
Medium Priority
?
431 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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 …
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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