order by multiple columns [message #598004] |
Wed, 09 October 2013 13:15 |
|
anncao
Messages: 87 Registered: August 2013
|
Member |
|
|
I have a query to pull the first contact of students.
The table has all contacts like parent/guardian, friends family, emergency contact etc.
I would like to the first primary contact in this order,
1. initial contact, 2. same as student address and also have to be parents,
3. live with and also a parent, 4. parents 5. friends.
I don't know how to pull 2 and 3 . because it looks like it needs to concatenate the columns.
here is my initial query
Select Min(U2.Id) Keep (Dense_Rank First Order By U2.Initial_Contact Desc, U2.Same_As_Students_Address Desc,u2.lives_with DESC,U2.Guardian Desc)
From Contacts
how to achieve 2 and 3?
The table script is attached. All the above columns are 1 or 0.
-
Attachment: table.txt
(Size: 2.50KB, Downloaded 1175 times)
|
|
|
Re: order by multiple columns [message #598005 is a reply to message #598004] |
Wed, 09 October 2013 13:18 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Hi,
Please post the table DDLs and insert statements. The rule which you have stated is a bit vague. How are those 5 values stored, insert statements will help us better understand the data.
|
|
|
|
Re: order by multiple columns [message #598010 is a reply to message #598008] |
Wed, 09 October 2013 13:39 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
I am afraid, not everybody like me would like to open/save the attachment. Please post the same thing using [ code] [ /code] tags(without the spaces I mentioned after the braces).
|
|
|