Click here to Skip to main content
15,909,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Given the table from Fig.1, write an SQL Select statement that would re-organize the results to look like Fig.2

Region | Contact
Cape Town | Fred
CapeTown | Joe
Cape Town | Anna
Durban | John
Durban | Mary
Johannesburg| Frank
Fig. 1

Region| Contact
Durban| John
Durban| Mary
Johannesburg| Frank
Cape Town| Anna
Cape Town| Fred
Cape Town| Joe
Fig. 2
Posted
Updated 18-Dec-12 7:33am
v2
Comments
[no name] 18-Dec-12 12:57pm    
Thomas Daniels 18-Dec-12 12:58pm    
http://www.whathaveyoutried.com/ is a shorter link.
Member 9374423 18-Dec-12 13:03pm    
SELECT Region,Contact From tblContacts
ORDER BY 1 DESC
Group By Region

this will only order it in alphabetic order, as seen cape town is below the rest of the regions in the below section.
joshrduncan2012 18-Dec-12 13:09pm    
Can you elaborate more as to how Fig 2 is sorted?
Member 9374423 18-Dec-12 13:21pm    
I want to sort fig 1 so that it looks exactly like figure 2

1 solution

Select Region, Contact From tblContacts
Order by Region, Contact
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900