Solved

one query and one result set

Posted on 2014-03-03
7
264 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

16 Experts available now in Live!

Get 1:1 Help Now