6 Sorting Data with ORDER BY - A Funny Take with Amit Bhadana Characters Part 2




Suppose we have a table named "amit_bhadana_characters" with the following columns: "name", "age", and "catchphrase". Here are some sample rows:
nameagecatchphrase
Amit Bhadana27"Aalas Hatao, Life Banao"
Babloo bhaiya35"Babloo Bhaiya ka style"
Sameer bhaiya30"Kya bolte bantai"
Genda bhaiya40"Hum Genda bhaiya hai"
Now let's say we want to sort this table based on the "age" column in ascending order. We would use the following SQL statement:Copy code

SELECT * FROM amit_bhadana_characters ORDER BY age ASC;


This would give us the following result:
nameagecatchphrase
Amit Bhadana27"Aalas Hatao, Life Banao"
Sameer bhaiya30"Kya bolte bantai"
Babloo bhaiya35"Babloo Bhaiya ka style"
Genda bhaiya40"Hum Genda bhaiya hai"


Similarly, if we want to sort in descending order, we would use the following SQL statement:

SELECT * FROM amit_bhadana_characters ORDER BY age DESC;


This would give us the following result:
nameagecatchphrase
Genda bhaiya40"Hum Genda bhaiya hai"
Babloo bhaiya35"Babloo Bhaiya ka style"
Sameer bhaiya30"Kya bolte bantai"
Amit Bhadana27"Aalas Hatao, Life Banao"
So, we can see that the ORDER BY clause is used to sort the results of a SELECT statement based on one or more columns. With the help of Amit Bhadana's characters, we can understand this concept in a fun and easy way.


Comments