How to use ORDER BY query in MySQL

ORDER BY Query:

  • 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- 

Query-
insert into employee
( Emp_ID,FirstName,LastName,Department,Mobile_No,Salary,Address)
values(5776,’Zahid’,’Iqbal’,’Computer’,12345,11000,’Chandigarh’)

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-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

1. STRING DATA TYPES-
The following are the String Datatypes in MySQL:

String Data Types

2. NUMERIC DATATYPES-

The following are the Numeric Datatypes in MySQL:

Numeric Data Types

3. DATE/TIME DATATYPES-

The following are the Date/Time Datatypes in MySQL:

Date-Time

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

SQL COMMANDS: DDL,DML, TCL, DCL

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

DML:

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

DCL:

Data Control Language (DCL) statements. Some examples:

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

TCL:

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