Click here to Skip to main content
15,881,852 members
Home / Discussions / Database
   

Database

 
GeneralRe: Un-natural sort order... Pin
Nic Rowan10-Oct-05 1:14
Nic Rowan10-Oct-05 1:14 
GeneralRe: Un-natural sort order... Pin
ModuleKev10-Oct-05 1:15
ModuleKev10-Oct-05 1:15 
AnswerRe: Un-natural sort order... Pin
Nic Rowan10-Oct-05 1:11
Nic Rowan10-Oct-05 1:11 
GeneralRe: Un-natural sort order... Pin
ModuleKev10-Oct-05 1:24
ModuleKev10-Oct-05 1:24 
GeneralRe: Un-natural sort order... Pin
Nic Rowan10-Oct-05 1:48
Nic Rowan10-Oct-05 1:48 
GeneralRe: Un-natural sort order... Pin
ModuleKev10-Oct-05 1:52
ModuleKev10-Oct-05 1:52 
AnswerRe: Un-natural sort order... Pin
miah alom10-Oct-05 5:01
miah alom10-Oct-05 5:01 
GeneralRe: Un-natural sort order... Pin
ModuleKev10-Oct-05 5:56
ModuleKev10-Oct-05 5:56 
Bingo!!! THANK YOU!!

The final 'order by' on the above in SQL Server, orders the entire rowset. But the above got me thinking, along with Colins original answer of adding a 0, 1 column.

I thought a group by on the individual columns may work, but since my country_id's are all over the place (secondhand data!), that was a no-go. Then thought about adding a 'magic' column to help with the order by.

Finally I've got this, which is exactly what I've been wanting to achieve (n.b. I've got several breakdowns of the UK: United Kingdom (Mainland), United Kingdom (Northern Ireland), etc ):

SELECT country_id, country_name, 0 as seed
FROM country
WHERE country_name LIKE 'United Kingdom%' OR country_name = 'United States'
UNION ALL
SELECT country_id, country_name, 1 as seed from country
WHERE country_name NOT LIKE 'United Kingdom%' AND country_name != 'United States'
ORDER by seed, country_name

I only vaguely remembered that there was a way to do this because I got asked it in an interview earlier in the year, but just couldn't remember how to do it!

Once again THANK YOU!!!!!!!
Smile | :) Big Grin | :-D Smile | :) Big Grin | :-D Smile | :) Big Grin | :-D Smile | :)
GeneralRe: Un-natural sort order... Pin
miah alom10-Oct-05 6:31
miah alom10-Oct-05 6:31 
QuestionHow to find table in Access databse??? Pin
Rohan_bhat_319-Oct-05 21:42
Rohan_bhat_319-Oct-05 21:42 
AnswerRe: How to find table in Access databse??? Pin
S Douglas20-Oct-05 23:38
professionalS Douglas20-Oct-05 23:38 
GeneralRe: How to find table in Access databse??? Pin
Rohan_bhat_3121-Oct-05 0:03
Rohan_bhat_3121-Oct-05 0:03 
GeneralRe: How to find table in Access databse??? Pin
S Douglas21-Oct-05 0:19
professionalS Douglas21-Oct-05 0:19 
QuestionList of databases on mySQL server Pin
Golden Dragon9-Oct-05 14:08
Golden Dragon9-Oct-05 14:08 
QuestionMySQL - delete current row Pin
Junyor9-Oct-05 11:50
Junyor9-Oct-05 11:50 
Questionperformance? Pin
hassan azizi8-Oct-05 17:03
hassan azizi8-Oct-05 17:03 
QuestionSystem DB Pin
Ranoush7-Oct-05 21:55
Ranoush7-Oct-05 21:55 
AnswerRe: System DB Pin
S Douglas20-Oct-05 23:33
professionalS Douglas20-Oct-05 23:33 
QuestionGenerate Create Script will not show up in Database Project in VS.NET Pin
Pitchiah4u7-Oct-05 21:38
Pitchiah4u7-Oct-05 21:38 
Questioncheckbox in datagrid Pin
ahager7-Oct-05 7:07
ahager7-Oct-05 7:07 
QuestionManagment studio Pin
Bueto7-Oct-05 3:52
Bueto7-Oct-05 3:52 
AnswerRe: Managment studio Pin
Bueto9-Oct-05 22:54
Bueto9-Oct-05 22:54 
QuestionSQL Pin
shoaibnawaz6-Oct-05 10:34
shoaibnawaz6-Oct-05 10:34 
AnswerRe: SQL Pin
Colin Angus Mackay6-Oct-05 12:35
Colin Angus Mackay6-Oct-05 12:35 
GeneralRe: SQL Pin
shoaibnawaz7-Oct-05 11:50
shoaibnawaz7-Oct-05 11:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.