How to use ORDER BY query in MySQL


  • used to sort the result-set by one or more columns
  • ORDER BY keyword sorts the records in ascending order by
  • To sort the records in a descending order, you can use the
  • By default, it’s ascending order

Query –

select Salary from employee order by Salary Order By




select Emp_ID,FirstName,LastName,Department,Mobile_No,Salary,Address from employee order by Salary

Order By Data

How to insert data into table in MySQL

Insert data into table- 

insert into employee
( Emp_ID,FirstName,LastName,Department,Mobile_No,Salary,Address)

Insert Data into the tableImport the data from excel 

  • Data should be arrange in the table format and save the .csv format
  • Now select the import and choose the file
  • Now data are inserted into the table.

Import tha data from excel

After inserting the data table is-

Final table

MySQL Data Types


MySQL supports a number of data types in several categories:
1. String (character and byte) types, and spatial types.
2. Date and time types
3. Numeric types

The following are the String Datatypes in MySQL:

String Data Types


The following are the Numeric Datatypes in MySQL:

Numeric Data Types


The following are the Date/Time Datatypes in MySQL:


What are the difference between DDL, DML and DCL commands?


SQL commands are instructions used to communicate with the database to perform specific task that work with data. SQL commands can be used not only for searching the database but also to perform various other functions like, for example, you can create tables, add data to tables, or modify data, drop the table, set permissions for users. SQL commands are grouped into four major categories depending on their functionality:

DDL : 

Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:

  • CREATE – to create objects in the database
  • ALTER – alters the structure of the database
  • DROP – delete objects from the database
  • TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
  • COMMENT – add comments to the data dictionary
  • RENAME – rename an object


Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:

  • SELECT – retrieve data from the a database
  • INSERT – insert data into a table
  • UPDATE – updates existing data within a table
  • DELETE – deletes all records from a table, the space for the records remain
  • MERGE – UPSERT operation (insert or update)
  • CALL – call a PL/SQL or Java subprogram
  • EXPLAIN PLAN – explain access path to data
  • LOCK TABLE – control concurrency


Data Control Language (DCL) statements. Some examples:

  • GRANT – gives user’s access privileges to database
  • REVOKE – withdraw access privileges given with the GRANT command


Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.

  • COMMIT – save work done
  • SAVEPOINT – identify a point in a transaction to which you can later roll back
  • ROLLBACK – restore database to original since the last COMMIT
  • SET TRANSACTION – Change transaction options like isolation level and what rollback segment to use