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

x
?
Solved

one query and one result set

Posted on 2014-03-03
7
Medium Priority
?
271 Views
Last Modified: 2014-03-03
select * from a_messages where profile_id='username' order by message_id desc
select * from a_messages2 where profile_id='username' order by message_id desc


want one query with one result set because tables have same structure
0
Comment
Question by:rgb192
[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
7 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 39900597
select * from a_messages where profile_id='username' order by message_id desc
UNION
select * from a_messages2 where profile_id='username' order by message_id desc
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1500 total points
ID: 39900602
use UNION ALL:
select * from a_messages where profile_id='username' 
UNION ALL
select * from a_messages2 where profile_id='username' 
order by message_id desc 

Open in new window

0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39900604
#@(*&Q#(*(&$ ANGELLLL!!!!!!

LOL

one misype :(
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1500 total points
ID: 39900609
note: UNION ALL will not try to do an implicit DISTINCT, so unless you really want to do that, ALWAYS use union all.
and order by is only at the end of the query, so you cannot do the "per" table, but only once per "result", so the comment before mine is unfortunately incorrect in that regards ...
0
 
LVL 23

Assisted Solution

by:Steve Wales
Steve Wales earned 500 total points
ID: 39900611
Not necessarily a mistype.

UNION returns a distinct result set (does not show duplicates).
UNION ALL returns all rows, regardless of duplicates.

Depends what the original poster wants in the result set, I suppose :)
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39900619
i know its a monday I wasn't quite awake yet and i dont drink coffee
  :)
0
 

Author Closing Comment

by:rgb192
ID: 39900656
http://www.experts-exchange.com/M_4365474.html

Error Code: 1221. Incorrect usage of UNION and ORDER BY


second query worked

thanks for explanations also
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

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.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
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

671 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