Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Reporting with SQL Ordering, Limiting and Paging Results Practice Session

SELECT *FROM movies ORDER BY DESC; Will this query give me back an output? Is it incomplete statement?

Will this query give me output? Is this an incomplete statement?

5 Answers

Keenan Johnson
Keenan Johnson
13,841 Points

What are you ordering by? I haven't run this code but I believe that's your issue. I believe it should be:

SELECT *
FROM movies
ORDER BY [column_name] DESC

You need to provide a <column> to order, or else you're going to get a syntax error.

Now as far as arranging the entire table in order, it's already arranged based on the order the rows were entered. It's simply not possible to arrange a table with mixed data types like string, dates, integers, etc - hence the ORDER BY keyword.

Hi

Is it acceptable to not ORDER BY column name but do Tables instead.. Can I order by Table as a whole?

Monica Dhulipudi I don't think that'd be possible (ordering by a table), because it wouldn't know where to start/prioritize. Which column gets sorted first? And you couldn't sort columns separately, bc the entire row is locked/connected together.

So, let's say you had Last Name, First Name, Phone as your columns. Even if you did ORDER BY last_name, first_name, the First Name column would only get sorted if the Last Names were the same. Otherwise, if our data was Jane Smith and Suzie Donut, our results would give us Jane Donut and Suzie Smith, which could be a little awkward. ;-)