Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old August 21st, 2009, 12:34 PM
Registered User
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 View Post
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.
Reply With Quote
  #12 (permalink)  
Old October 10th, 2009, 07:52 AM
shubhanker_techgeek
Guest
 
Posts: n/a
Default 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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UNION query. rupen Access 3 April 28th, 2006 02:49 AM
UNION of Tables neo_jakey Classic ASP Professional 2 January 31st, 2006 03:08 PM
Problem with UNION - Please Help brettk_1 SQL Server 2000 1 November 9th, 2004 08:08 AM
Order By with Union agarwalmk SQL Language 3 February 18th, 2004 11:33 AM



All times are GMT -4. The time now is 08:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.