|
|
 |
| SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Language section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |
|

August 21st, 2009, 01:34 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
UNION and ORDER BY
Use index values from your select statement (note they start at 1 not 0)
For example if you have a select statement like this:
SELECT value1, value2, value3
Replace: ORDER BY value2, value3
With: ORDER BY 2, 3
This works with MySQL and Derby
Quote:
Originally Posted by grogi
Yes, this query works fine but if you only have distinct rows. If you have union from same table but with different filters then you'll have a duplicates in the result set because of the column OrderBY.
|
|

October 10th, 2009, 08:52 AM
|
|
Registered User
|
|
Join Date: Aug 2008
Location: calcutta, West Bengal, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
union with order by
I would suggest to code like this
select
name,
dob,
title
from
(
select tblA.name,tblA.CreateDay as dob,tblA.title
from tblA
union
select tblB.name,tblB.JoiningDATE as dob,tblB.title
from tblB
) unioned -- this can be any name including yours but its a must as it works --as alias
order by dob desc
happy coding
__________________
aran
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |