Viewers: in countries Watching now:
MySQL is by far the most popular database management system for small- to medium-sized web projects. In this course, Bill Weinman provides clear, concise tutorials that guide you through creating and maintaining a MySQL database of your own. Bill explores the basic syntax, using SQL statements to create, insert, update, and delete data from your tables. He also covers creating a new database from scratch, as well as data types, transactions, subselects, views, and stored routines. Plus, learn about the multi-platform PHP PDO interface that will help you connect your database to web applications.
The order by clause is used to sort the results of a query, here's how it works. Select the world database here in SID. And if I say select name from country like that, you'll notice that the names are not in any particular order. Yeah a lot of the a's are before a lot of the b's but there's still other stuff you know, there's Switzerland in with the c's and it's not really in order. The order by clause is how you put things in order in your result sets.
So if I say order by name and select Go, then it is now in alphabetical order by name. See all the c's are after all the b's and then there's the d's and you'll notice that they're all in order now. Now what if I don't want them in ascending order? So if instead I want it in descending order, I can just put DESC which is an SQL keyword after the word name and order by, so it's order by name descending is how that would read.
And I press Go and now I have the z's at the top followed by the y's and the w's and the v's and that's descending order. The natural default order is ascending and it does have a key word ASC, but it's also the default. And so it's usually omitted. Now if I want to here, I can sort by more than one thing. I can say name, continent, and I can order by continent, name. And now what it'll do is it'll put all the continents together and then all the names within the continents.
And so here we have the continent of Asia, and we have all of the countries in Asia. And they're in alphabetical order within that group, and then we have Europe. And we start again with the A's inside of Europe, and North America, and like that. So now we're sorting by 2 factors, we're sorting by continent and name within the continent. In fact if you want to, you can even have different sort orders within that list. Say for instance, I wanted Continent and Region and I want to order by continent, but I want the continent order to be descending and then within continent, I want region and name, ascending.
And so if I say Go, now we start with the South American continent and Antarctica continent and here's the Oceana continent, we have Australia and New Zealand first and then Malaysia and within each of those, we have the alphabetical order by country name. So, we're combining descending and ascending sort orders within the one ORDER BY clause. So, the ORDER BY clause is used to sort the results of your queries. You can sort on multiple columns and you can choose ascending or descending collations according to your requirement.
There are currently no FAQs about MySQL Essential Training.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.