SQL Challenge: Sorting Students by Last 3 Name Characters and ID

🚀 Day 5 – SQL Daily Challenge | Smart Sorting with Strings Today’s challenge focused on filtering and sorting data using string functions a small twist that really tests your understanding of SQL logic. 🔍 Problem: Query the names of students who scored more than 75 marks. Sort the results based on the last 3 characters of their names, and if multiple names share the same ending, sort them by ID (ascending). 🧠 Approach: Filter students with marks greater than 75 Use the RIGHT() function to extract the last 3 characters from each name Use these extracted characters for primary sorting Apply secondary sorting using ID for tie-breaking 💻 Solution: SELECT NAME FROM STUDENTS WHERE Marks > 75 ORDER BY RIGHT(Name, 3), ID; 📌 Key Learnings: ✔️ Using string functions like RIGHT() for sorting ✔️ Understanding multi-level sorting (ORDER BY) ✔️ Applying tie-breaker logic using ID ✔️ Realizing that sorting can be done on derived values, not just columns 💡 Takeaway: Even a simple dataset can introduce powerful concepts like custom sorting logic. Today’s challenge helped me understand how to manipulate strings and apply layered sorting effectively. 📌 Consistency continues — learning SQL one challenge at a time! #SQL #DataAnalytics #LearningInPublic #Day5 #30DaysChallenge #BeginnerJourney

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories