473,394 Members | 1,645 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,394 software developers and data experts.

Can we use two orderBy in single Select statement ?

Hi every one !

Im workin on SQL05, My Question is !

i have a single field "PosId" in the DB,which i use as two fields one as PosId and PosID2 , Even though Both PosID & PosID2 are from the same fields ,i want to sort the PosID in ascending and PosID2 in desc,
This is what i tried , But ???

"SELECT PosID,PosID as PosID2
FROM tableXX
WHERE (condition = 'XX')
ORDER BY PosID ASC,PosID2 DESC"

Can we use two order by in a single select statement ?
Or is there any alternative .

Plz provide me with a valid soln.
Thanks in advance,
Apr 18 '08 #1
3 1462
ck9663
2,878 Expert 2GB
Hi every one !

Im workin on SQL05, My Question is !

i have a single field "PosId" in the DB,which i use as two fields one as PosId and PosID2 , Even though Both PosID & PosID2 are from the same fields ,i want to sort the PosID in ascending and PosID2 in desc,
This is what i tried , But ???

"SELECT PosID,PosID as PosID2
FROM tableXX
WHERE (condition = 'XX')
ORDER BY PosID ASC,PosID2 DESC"

Can we use two order by in a single select statement ?
Or is there any alternative .

Plz provide me with a valid soln.
Thanks in advance,
I don't know what you're trying to accomplished. But if that's really your requirement, the answer is NO. You can not do it in a single select statement. You can, however, do it using subquery

Something like:

Expand|Select|Wrap|Line Numbers
  1. select * from 
  2. (SELECT     PosID,PosID as PosID2
  3. FROM         tableXX
  4. WHERE     (condition = 'XX')) YourTableXX
  5. ORDER BY PosID ASC,PosID2 DESC
  6.  
-- CK
Apr 18 '08 #2
I don't know what you're trying to accomplished. But if that's really your requirement, the answer is NO. You can not do it in a single select statement. You can, however, do it using subquery

Something like:

Expand|Select|Wrap|Line Numbers
  1. select * from 
  2. (SELECT     PosID,PosID as PosID2
  3. FROM         tableXX
  4. WHERE     (condition = 'XX')) YourTableXX
  5. ORDER BY PosID ASC,PosID2 DESC
  6.  
-- CK
Thanks for your response, Well ! it worked partialy in displaying the same field in the data set but, one should be in ascending and other should be in descending order !

The above code didnt sort the PosID in desc order ?
Jun 3 '08 #3
ck9663
2,878 Expert 2GB
Could you post some sample data?

If you are sorting the same field in different order, it will not work. Since your POSID will always be equal to POSID2 (since POSID2 is an alias), it will always be sorted by POSID.

-- CK
Jun 3 '08 #4

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

Similar topics

5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
6
by: P. Emigh | last post by:
By default in more recent versions, Access forms keep users' last sort request in the "orderby" property. That can slow things down considerably, especially when the last user has chosen a...
2
by: DFS | last post by:
Access97: I opened a report, then opened a small form that floats above it and lets you choose report fields to sort on (by issuing the OrderBy statement). Well, apparently OrderBy actually...
2
by: Todd | last post by:
Hello, I'm curious if anyone knows of a way (if one exists) to tell a form (in Access 2002 VBA) to sort on an unbound column of a combo box on the form. Here's what I want to do: A combo box...
2
by: Dutchy | last post by:
Hi there, After spending several hours trying all I could imagine and search for in Google I gave up. In a continuous form I want to sort the choosen column by clicking the header (label) of...
1
by: fecket | last post by:
The following code is used in my db to change the sort order of the report to various fields. I want to take this one stage further and use maybe a Case Select to give 2 or 3 different options to...
7
by: pbd22 | last post by:
Hi. I really need some advice on fine-tuning a stored procedure that is the meat of the search logic on my site. Customers are allowed to save searches, which dumps the search logic in a table...
0
by: dhascuba | last post by:
The @name field can contain a single quote in it such as: Mike O'Grady. Since this is creating and SQL statement on the server side, it will not process the name if it has a single quote in it. Id'...
4
by: Marc Gravell | last post by:
Ah right - I just saw your explanation of "Source"; yes - I'd have 2 queries, then: switch(Source) { case "File": viewData.blah = (from t in database.Tags where t.FileCount != 0 orderby...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.