Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

UNION SQL QUERY dosent return the right result

Posted on 2012-09-07
3
Medium Priority
?
567 Views
Last Modified: 2012-09-07
Hi,

I have a union sql query (please see the code).
When I run this query it returns 2900 rows, but each table has aproximatly 1 milion records.
It seems to me that the MySql returns only the unique records.
How can I make it work?

Thank you,

SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120814 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120815 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120816 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120817 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120818 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120819 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120820 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120821 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120822 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120823 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120824 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120825 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120826 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120827 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120828 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120829 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120830 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120831 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120901 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120901 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120902 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120902 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120903 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120903 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120904 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120904 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120905 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120905 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120906 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120906 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120907 WHERE Type=1 UNION SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120907 WHERE Type=1

Open in new window

0
Comment
Question by:Qw M
  • 2
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 38375836
Replace your UNIONs  with "UNION ALL"
0
 

Author Comment

by:Qw M
ID: 38375861
@mbizup - Now I get an error - MySql Server has gone away
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38375879
Start with a manageable portion of your query, to make sure you have the syntax right:

SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120814 WHERE Type=1 UNION ALL SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120815 WHERE Type=1 UNION ALL SELECT Project, Desk, Action, Field FROM tbhy_logdata_20120816 WHERE Type =1 

Open in new window


Then add to it...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

580 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