Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

order by ?? Expand / Collapse
Author
Message
Posted Friday, February 11, 2011 7:52 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, March 26, 2014 6:46 AM
Points: 1,776, Visits: 1,199
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
Post #1062610
Posted Friday, February 11, 2011 8:50 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, April 21, 2014 6:15 AM
Points: 67, Visits: 359
What are the data types of these columns? Also, could you be more specific than "it isn't working"?

Jim
Post #1062638
Posted Friday, February 11, 2011 9:24 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:16 PM
Points: 12,755, Visits: 31,121
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1062667
Posted Monday, February 14, 2011 10:46 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, May 01, 2012 12:43 AM
Points: 63, 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
Post #1064014
Posted Wednesday, February 16, 2011 1:45 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, March 26, 2014 6:46 AM
Points: 1,776, Visits: 1,199
Thank you Amartha dutta
Post #1064766
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse