473,405 Members | 2,310 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,405 software developers and data experts.

Order by results by different columns

23
Hi all
I have results with different columns and i want to order the data according to different columns under different conditions.

I have four columns: isflagged(T/F), FlaggedAt(Time), createdAt(time),updatedAt(time).

For the rows which have isFlagged as T, i want them at top in result, order by FlaggedAt descending.
and for the rows which have isFlagged as F , want them to be order by createdAt when created is not null otherwise by updatedAt.


How can I acheieve this,

Thanks
Feb 14 '08 #1
2 1480
harshmaul
490 Expert 256MB
have you tried splitting the select into two, ordering them both seperately, and then unioning (if thats a word) them together....

Expand|Select|Wrap|Line Numbers
  1. select * from tbl where isFlagged = 't' Order By X
  2. UNION
  3. select * from tbl where isFlagged = 'f' Order By Y
  4. UNION
  5. select * from tbl where isFlagged = null Order By Z
Feb 14 '08 #2
ronverdonk
4,258 Expert 4TB
have you tried splitting the select into two, ordering them both seperately, and then unioning (if thats a word) them together....

Expand|Select|Wrap|Line Numbers
  1. select * from tbl where isFlagged = 't' Order By X
  2. UNION
  3. select * from tbl where isFlagged = 'f' Order By Y
  4. UNION
  5. select * from tbl where isFlagged = null Order By Z
You cannot ORDER within a UNION select clause.

Ronald
Feb 14 '08 #3

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

Similar topics

2
by: Dave | last post by:
I'm getting different results when I display a value in the Output window as opposed to the Immediate window. Why? Code to recreate problem: 'Purpose: Get different results from Output...
0
by: Rob | last post by:
Hi I have a dataset that is ordered by the primary key, but when I view it in a dataview with the sort propery filled in with the primary key, the order is different. The data that seems to cause...
1
by: Leon | last post by:
Hi! Does anyone knows this problem? When I'm changing view to DS then I'm selecting fiew columns and I'm tying to "print selected records" I obtain different columns on my just printed page...
1
by: Leon | last post by:
Hello again! I post this message once again because I've noticed this kind of behavior in: A2k (mdb,adp) and RunTime. The problem is: When I'm changing view to DS then I'm selecting fiew...
1
by: nm | last post by:
How can I change the order of DataGrid columns? I have a Master-Detail relationship and the columns in the datagrid look like they are lined up in alphabetical order which is not what I want.
2
by: Thomas Beyerlein | last post by:
Is it possible to have different columns of a datagrid bound to different datatables? I am working on a project and the specks have suddenly changed. Now a item can have multiple reports/...
2
by: =?Utf-8?B?Z2FuZQ==?= | last post by:
Hi, In a gridview, How can i display different columns between item and edit modes. For eg. i have a sql that returns productname, categoryname, etc. In viewmode, i need to display only...
9
by: tabakaka | last post by:
i need to connect 2 different columns from 2 tables. note the these columns are strings (varchar) column on 1st table: description1 column on 2nd table: description2 example: description1:...
1
by: chopin | last post by:
I was wondering if there was a way to alternate data taken from two different columns in a query, then placing that data into a another query or table. For example, let's say I have the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

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.