Solved

one query and one result set

Posted on 2014-03-03
7
268 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Amazon Redshift 2 43
Excel - SQL export question 3 53
mysql query for sum() 3 47
MySqli Real Escape String and SQL Injection 1 44
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Creating and Managing Databases with phpMyAdmin in cPanel.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

761 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