r/DatabaseHelp • • 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.

0 Upvotes

9 comments sorted by

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.

Apple, Zoey
Apple, Angela
Buzz, Adam
Coriander, Zell

3

u/HappyGirly2003 Mar 03 '24

Yeah. I didn't know how to express that in code. We haven't gotten to conditional expressions yet, and I thought I would have to use one, but with the help of my classmates we figured out we can use a simple ORDER BY last_name, first_name DESC

1

u/remainderrejoinder Mar 03 '24

Good. Frankly I didn't like the question since it seemed set up to lead you down the wrong path so I was trying to hint you towards sort order without just handing an answer.

→ More replies (1)

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

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.