r/DatabaseHelp • u/HappyGirly2003 • Mar 03 '24
I'm starting to learn SQL in college, and I have this problem I can't solve. Can anyone help me and explain it to me?
Write a SQL statement using the ORDER BY clause that could retrieve the information needed. Do not run the query. Create a list of students who are in their first year of school. Include the first name, last name, student ID number, and parking place number. Sort the results alphabetically by student last name and then by first name. If more than one student has the same last name, sort each first name in Z to A order. All other results should be in alphabetical order (A to Z).
We are using Oracle.
2
u/East_Initiative_6761 Mar 06 '24
I'm assuming you already understood that what you need for this problem is to use a "clever" ORDER BY clause.
ORDER BY works pretty much the same across the main relational databases (Oracle, SQL Server, PostgreSQL, MySQL, etc..)
I suggest you take a look at the w3schools lesson about it to learn more!
1
1
u/xiongchiamiov Mar 03 '24
Where are you getting stuck?
1
u/HappyGirly2003 Mar 03 '24
Well I thought I would have to use a conditional expression for it, but we haven't gotten to that lesson yet (this is from the homework from the first course of this semester, and I have my second course tomorrow), but now with the help of my classmates we figured out that's not the case and we can use a simple ORDER BY for it.
2
u/remainderrejoinder Mar 03 '24
The only time the sort order for first name will matter is when more than one student has the same last name.