SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


order by ??


order by ??

Author
Message
Marimuthu-129612
Marimuthu-129612
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2103 Visits: 1546
I have table like this

col1 col2 col3
5 3 8
6 2 9
7 1 10

and i want result as

col1 col2 col3
5 1 8
6 2 9
7 3 10
ie, col2 also in ascending order.

What is the query..?

Order by col1 asc,col2 asc, col3 asc is not working..please check
skt5000
skt5000
SSC Journeyman
SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)

Group: General Forum Members
Points: 75 Visits: 435
What are the data types of these columns? Also, could you be more specific than "it isn't working"?

Jim
Lowell
Lowell
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35901 Visits: 40249
your example's messing you up... a row of data is just that: each element is related to the others. grabbing a value from another row? why?

if you substitute names for your numbers, you'll see why it doesn't seem right:

col1 col2 col3
George Washington Virginia --5 3 8
Abraham Lincoln Illinois --6 2 9
Bill Clinton Arkansas -- 7 1 10

would you really want:

col1 col2 col3
George Clinton Virginia --5 1 8
Abraham Lincoln Illinois --6 2 9
Bill Washington Arkansas --7 3 10



show us the REAL code(not the pseudo code you tried to show as an example) so we can really help you.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Dutta, Amartha
Dutta, Amartha
SSC-Enthusiastic
SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)SSC-Enthusiastic (125 reputation)

Group: General Forum Members
Points: 125 Visits: 110
SELECT
tCOL1COL3.COL1 AS COL1,
tCOL2.COL2 AS COL2,
tCOL1COL3.COL3 AS COL3
FROM
(
SELECT
COL1,
COL3,
RANK () OVER(ORDER BY COL1 ASC) AS ROWNUMBER
FROM
SQLSerC /* YOUR TABLE HAVING COLUMNS COL1 (INT), COL2(INT), COL3(INT) */
) tCOL1COL3
INNER JOIN
(
SELECT
COL2,
RANK () OVER(ORDER BY COL2) AS ROWNUMBER
FROM
SQLSerC /* YOUR TABLE HAVING COLUMNS COL1 (INT), COL2(INT), COL3(INT) */
) tCOL2
ON
tCOL1COL3.ROWNUMBER = tCOL2.ROWNUMBER

Sample Run Results ...

RunStatus COL1 COL2 COL3
Before Run ... 5 3 8
Before Run ... 6 2 9
Before Run ... 7 1 10


RunStatus COL1 COL2 COL3
After Run ... 5 1 8
After Run ... 6 2 9
After Run ... 7 3 10
Marimuthu-129612
Marimuthu-129612
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2103 Visits: 1546
Thank you Amartha dutta
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search