Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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

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.
  #12 (permalink)  
Old October 10th, 2009, 07:52 AM
Posts: n/a
Default union with order by

I would suggest to code like this

select tblA.name,tblA.CreateDay as dob,tblA.title
from tblA


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

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

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