Arrange the given keywords in the correct order of syntax where having select GROUP BY from ORDER BY
The Show ORDER BY SyntaxSELECT column1, column2, ... Demo DatabaseBelow is a selection from the "Customers" table in the Northwind sample database: CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden ORDER BY ExampleThe following SQL statement selects all customers from the "Customers" table, sorted ascending by the "Country" and descending by the "CustomerName" column: In this article, I will show you a few code examples on how you can sort your data in ascending order using the 1 clause in SQL.ORDER BY syntaxThis is the basic syntax to sort your data in ascending order:
If you want to sort by descending order, then you have to use the 2 keyword.
The 3 statement in SQL tells the computer to get data from the table.The 4 clause in SQL specifies which table we want to list.In this example, we have a table of musicians with the columns of 5, 6, 7, 8 and 9:Right now, this table is sorted automatically by 5 in ascending order.If we wanted to sort the 6 column in ascending order, then we would have to use this syntax:
The 2 character tells the computer to select all of the columns in the table.You can see that the 3 are now sorted alphabetically and the 5's are no longer in the correct ascending order.If we wanted to sort the data by 9, then we can use this syntax.
You can also sort multiple columns in ascending order in the same command. In this new musician example, we can sort the 7 and 9 columns in ascending order.
We can see there are three 19 year old musicians with their respective cities alphabetically sorted in the table. We can also see the two 38 year old musicians with their cities properly sorted in alphabetical order. If we wanted to sort some of the data in ascending order and other data in descending order, then we would have to use the 8 and 2 keywords.In this new musician example, we want to sort the 7 column in descending order and the 8 column in ascending order.Here is the syntax:
We have to use both the 8 and 2 keywords next to the column names to tell the computer how to sort the data.The result would look like this: We can see in our table that both Oscar and Jenny are the oldest. But Oscar is the top result because drums comes before trombone alphabetically. We see the same situation with Jess and Dave. Even though they are the same age, Jess is higher in the table because flute comes before trumpet alphabetically. ConclusionYou can sort your table data in ascending order using the 1 clause in SQL.
If you want to sort by descending order then you also have to use the 2 keyword.
The 2 character tells the computer to select all of the columns in the table.
If you want to sort multiple columns in ascending order then you would list the columns you want to sort next to the 1 clause.
If you want to sort some of the data in ascending order and other data in descending order, then you would have to use the 8 and 2 keywords. 0That is how to use the 1 clause in SQL to sort data in ascending order.ADVERTISEMENT ADVERTISEMENT ADVERTISEMENT I am a musician and a programmer. If you read this far, tweet to the author to show them you care. Tweet a thanks Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started Which is the correct syntax for ORDER BY keyword?The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns. By default ORDER BY sorts the data in ascending order. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
What is the order of WHERE GROUP BY having ORDER BY?The Having Clause should be placed after the Group By clause, but before the Order By clause.
What is the order of WHERE GROUP BY and ORDER BY in SQL?The GROUP BY clause follows the WHERE clause and comes before the ORDER BY clause.
Which is the correct syntax for GROUP BY clause?Syntax for Group By in SQL
SELECT column1, function(column2) FROM table WHERE condition GROUP BY column1, column2 ORDER BY column1, column2; function: function applied on the columns exp, SUM() , AVG(). table: Name of the table used. condition: Condition used.
|