Need help with ORDER BY + IN combination, I can't figure out how to solve this question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need help with ORDER BY + IN combination, I can't figure out how to solve this question

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 clause. I tried: SELECT LastName, Country From Customers ORDER BY Country IN ('Canada', 'USA'), CustomerID ; It isn't working, I can't use WHERE cause it's supposed to list customers from all countries afterwards

7th Apr 2018, 1:40 PM
Anastasia Shereshevskaya
Anastasia Shereshevskaya - avatar
3 Answers
+ 4
You wrote Country wrong. You are not selecting ID. Try this SELECT CustomerID, LastName, Country From Customers ORDER BY FIELD(Country, "Canada," "USA"), CustomerID
7th Apr 2018, 1:55 PM
Toni Isotalo
Toni Isotalo - avatar
0
thx but I checked, I miss typed here but not there and the condition of the task is to specifically us IN in the ORDER BY clause ps I corrected the typo above, thx
7th Apr 2018, 2:04 PM
Anastasia Shereshevskaya
Anastasia Shereshevskaya - avatar
0
figured it out! it needs DESC or ASC after the ORDER BY Country (....) lol and now it works!
11th Apr 2018, 9:19 AM
Anastasia Shereshevskaya
Anastasia Shereshevskaya - avatar