Solved

one query and one result set

Posted on 2014-03-03
7
270 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 375 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 375 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 22

Assisted Solution

by:Steve Wales
Steve Wales earned 125 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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 …
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

632 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