Hi everybody,
I've got a problem with this SQL-Statement: - (SELECT * FROM currencies WHERE name = 'EUR') UNION ALL (SELECT * FROM currencies WHERE name = 'USD')
-
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
1 2052 Atli 5,058
Recognized Expert Expert
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: -
SELECT
-
c.`Name`,
-
(CASE c.`Name`
-
WHEN 'EUR' THEN 1
-
WHEN 'USD' THEN 2
-
ELSE 3
-
END) AS `DisplayOrder`
-
FROM `Currency` AS c
-
ORDER BY `DisplayOrder`, `Name` DESC;
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 SQL commands will return the same result but one
of my friends don't think so. He said "QUERY 1" will return 1 unsorted
record (ROWNUM < 2 ) first then sort the result (ORDER BY COL1 ASC,
|
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 particular
question.
I have a stored procedure that gets the column names in a particular
format (i.e. "chassis_id"|"chassis_description"|"modify_date") as well
as actual data for a given table (in a quote-separated, pipe-delimited
|
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 there a bug in
MySQL 4.1.
----------------------------8<----------------------------
(
select
|
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 Geographic
5 US
|
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 in the cross-reference table to the values table, call
them company and state. it's a transitive closure. along the way,
naturally, more columns have been added, call them region and division.
so that now, the unique identifier from the...
| |
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
appreciated. Thank you.
|
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.
|
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 floats to the top. Can someone help me?
Below is the SQL that does not run. Error is "Invalid column name 'name':
Select 0 as , 'PRIME' as
UNION
Select
subcontractor.subcontractorID, subcontractor.
from
subcontractor
|
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 that have a date sorted in Descending order by date, then the Titles that don't have a date sorted by Title in Ascending order.
I have this:
SELECT & " " & "(" & & ")" AS Expr1
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |