473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

UNION ignores my embedded ORDER clause

1
Hi everybody,
I've got a problem with this SQL-Statement:

Expand|Select|Wrap|Line Numbers
  1. (SELECT * FROM currencies WHERE name = 'EUR') UNION ALL (SELECT * FROM currencies WHERE  name = 'USD')
  2. UNION ALL (SELECT * FROM currencies WHERE name !='EUR' AND name != 'USD' ORDER BY name ASC)
The table "currencies" contains over 100 different currencies and I want get EUR first, then USD and at least the rest of the table in alphabetical order.

But the problem seems to be that the ORDER BY clause in the last SELECT is ignored. The Output is definitly not ordered in any way. I checked this by changing the order-direction to desc.
Am I just to stupid or is this a problem within MySQL ?

Greetz Piecko
Oct 28 '08 #1
1 2036
Atli
5,058 Expert 4TB
That's odd. I would have thought that should work.

I came up with an alternative tho.
You can simply add a integer column to your query and give that column a value that you can then sort the results based on. That is; if the name of the currency is 'EUR', then you give it the value 1. If it is 'USD', then you give it the value 2. If it is anything else, you give it the value 3.
Then you can simply have your ORDER BY clause sort the result by the integer column first, and then by then name column.

For example:
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.     c.`Name`,
  3.     (CASE c.`Name`
  4.         WHEN 'EUR' THEN 1
  5.         WHEN 'USD' THEN 2
  6.         ELSE 3
  7.     END) AS `DisplayOrder`
  8. FROM `Currency` AS c
  9. ORDER BY `DisplayOrder`, `Name` DESC;
  10.  
Oct 30 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following...
3
by: Blake Caraway | last post by:
All, I've seen several posts regarding using UNION or UNION ALL to mash together two or more resultsets into a single result set, but can't seem to find enough info here to help me answer my...
1
by: Tom Schindl | last post by:
Hi, the following Statement worked on MySQL 4.0 but after upgrading to 4.1.12 on win32 the order is not working any more. Is this a known problem or is our SQL simply not useable on 4.1 or is...
3
by: handaman | last post by:
I am having problems retrieving some data from a table, Tablename = "Magazine" Columns MagazineID MagazineName 1 2 Times 3 People 4 National...
4
by: robert | last post by:
before i go flapping my gums and get deeper in alligators, wondering whether the following makes sense. i have a database which provides picklists for input. it started out with a 2 column key...
4
by: shaun palmer | last post by:
when or Where do you use a union query ? how can I wright sql, tblPopulation,* tblcustomer,* one to one with all the appropriate attributes(field). Your help would be greatly...
2
by: S. van Beek | last post by:
Dear reader, The following code delivers a wild card in the result of the query. But the ORDER BY is not longer working.
4
by: tkltechy | last post by:
I have a sql query that unions two recordsets. It works when I don't try to adjust the ORDER BY clause using the replace function. However, I want to ensure that a certain item in the list always...
3
by: dontfwithchuck | last post by:
Hi, this is my first post. I use Access XP. I have a single table called Movies containing the following fields: ID, Title, Genre, Rating, Location, Date I want a datasheet with the Titles...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.