2012-06-19 19 views
6

यह मेरा SQL क्वेरी है:एसक्यूएल क्वेरी परिणाम व्यवस्था मुद्दा

select name,description 
from wp_widget_custom 
where name in ('hemel-hempstead','maidenhead', 
    'guildford','bromley','east-london','hertfordshire','billericay','surrey') 

परिणाम मैं हो रही है इस रूप में है:

name   description 
hemel-hempstead Loreum ipsim 
east-london  Loreum ipsim 
bromley   Loreum ipsim BROMLEY 
billericay  Loreum ipsim 
maidenhead  Loreum ipsim maidenhead 
hertfordshire Loreum ipsim HERTFORDSHIRE 
guildford  loreum ipsum Guildford 
surrey   loreum ipsum surrey 

मैं परिणाम जिस तरह से यह पारित किया गया था की व्यवस्था की जा करना चाहते हैं क्वेरी में:

hemel-hempstead ,maidenhead',guildford,bromley,east-london...... 

सहायता की सराहना की जाती है, धन्यवाद। क्षेत्र द्वारा

उत्तर

6

आदेश:

select name, description 
from wp_widget_custom 
where name in ('hemel-hempstead','maidenhead','guildford','bromley','east-london','hertfordshire','billericay','surrey') 
order by field(name, 'hemel-hempstead','maidenhead','guildford','bromley','east-london','hertfordshire','billericay','surrey') 
+0

+1 आसान मेरा उत्तर :) से उत्पन्न करने के लिए – Andomar

+0

ज़बरदस्त मैं कभी नहीं पता था कि हम चाहते हैं कि धन्यवाद –

+0

नाइस, सीखा जैसी मदों की व्यवस्था कर सकते कुछ नया :) –

1

आप एक फ़िल्टर inner join के बजाय एक where ... in खंड इस्तेमाल कर सकते हैं। यही कारण है कि आप एक आदेश है, जो आप तो order by खंड में संदर्भित कर सकते हैं निर्दिष्ट कर सकते हैं:

select wc.name 
,  wc.description 
from wp_widget_custom wc 
join (
     select 1 as nr, 'hemel-hempstead' as name 
     union all select 2, 'maidenhead' 
     union all select 3, 'guildford' 
     union all select 4, 'bromley' 
     union all select 5, 'east-london' 
     union all select 6, 'hertfordshire' 
     union all select 7, 'billericay' 
     union all select 8, 'surrey' 
     ) as filter 
on  filter.name = wc.name 
order by 
     filter.nr 
संबंधित मुद्दे