The marketing department wants to focus on the customers from North America first. Gets the ID, last name and country of all customers. Build the list by bringing up the customers living in Canada and in the USA first, and finally ordered them by ID. Tip: Use the IN expression in the ORDER BY help me please😯😐😐 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The marketing department wants to focus on the customers from North America first. Gets the ID, last name and country of all customers. Build the list by bringing up the customers living in Canada and in the USA first, and finally ordered them by ID. Tip: Use the IN expression in the ORDER BY help me please😯😐😐

5th Jul 2016, 7:33 PM
meri
meri - avatar
8 Answers
+ 4
@ meri - try this code : select customer ID, lastname, country from customer order by country in ('Canada', 'USA') desc, customer ID;
21st Jul 2016, 1:38 AM
Rosekamal
+ 2
can you share table structure please
6th Jul 2016, 10:50 AM
Ashutosh Singh
+ 2
Here is a better solution, without using IN expression. Let me know if it helps you out --> select id, lastname, country from tablename order by (case when country='US' then 0 when country='Canada' then 1 end) desc, id asc
12th Jul 2016, 9:15 AM
Ashutosh Singh
+ 1
I am also looking for an help to this question. for further note: the expected result needs to have country column values as - USA and Canada values listed first, followed by the values of all other countries down in the country column. So how a combination of nesting Order by and IN would help?
17th Jul 2016, 7:13 AM
Rosekamal
+ 1
Select Customerld, LastName, Country From customer Order by Country in ('Canada' , 'USA') DESC something like that...
9th Apr 2017, 3:34 PM
Дмитрий Кравченко
Дмитрий Кравченко - avatar
0
structur is so 59 rows, 9 columns:id ,firstname,lastname,city,state,country,email,invoicetotal,company that is all
8th Jul 2016, 8:17 PM
meri
meri - avatar
0
thanks @Rosekamal it is true answer
21st Jul 2016, 6:08 AM
meri
meri - avatar
0
Select Customerld, LastName, Country From customer Order by Country IN ('Canada' , 'USA') DESC
15th Mar 2018, 3:38 AM
Ganesh Sonule
Ganesh Sonule - avatar