Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL Order By Clause

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 199
    Comment on it

    With the help of SQL Order By statement we can sort our data in a table either in ascending order or descending order based upon the user, what he wants.
    Note -> Some Databases have already sort the data order by default .
    Syntax :

    select expression from table_name where clause order by expression Asc / Desc ;
    

    Example :
    Table name : Employee_Info

      Employee_name            Employee_Age          Employee _Salary
          Mukesh                  23                           100000
          Ayush                   24                           200000
          Ishan                   20                           400000
          Pranav                  35                           700000
          Abhishek                26                           800000
          Ravi                    25                           300000
          David                   40                           800000
    

    If i want to sort this table by ascending order then :

        select * from Employee_Info order by Employee_Name
    

    Output :

     
     Employee_name            Employee_Age          Employee _Salary
        Abhishek                26                           800000
        Ayush                   24                           200000
        David                   40                           800000
        Ishan                   20                           400000
        Mukesh                  23                           100000
        Pranav                  35                           700000
        Ravi                    25                           300000    
    

    If I want to sort this table by descending order then :

        select * from Employee_Info order by Employee_Name
    

    Output :

      Employee_name            Employee_Age          Employee _Salary
          Ravi                    25                          300000
          Pranav                  35                          700000
          Mukesh                  23                           100000
          Ishan                   20                           400000
          David                   40                           800000
          Ayush                   24                           200000
          Abhishek                26                           800000  
    

    With SQL Order By Clause we can do other task also like :
    1) SQL Order By Random -> Using this we can get our data in random order .
    2) SQL Order By Limit -> Using this we can get limited data from database .
    3) SQL Order By Multiple Columns -> Using this we can get sort data from multiple columns .

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: