Solved

one query and one result set

Posted on 2014-03-03
7
266 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
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 142

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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 142

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now