SQL_Examples
SQL_Examples
Method 2:
SYNTAX: INSERT INTO <Table_Name> VALUES (Value 1, Value 2,….);
EXAMPLE: INSERT INTO employee VALUES (1, “Mukesh”);
2. SELECT – It is used to retrieves or fetch the data from the table.
TO FETCH ENTIRE RECORD OF TABLE [* means ALL records]
SYNTAX: SELECT * FROM <Table_Name>;
EXAMPLE: SELECT * FROM employee;
TO FETCH RECORD OF SELECTED FIELDS FROM TABLE
SYNTAX: SELECT <Field1, Field2,…> FROM <Table_Name>;
EXAMPLE: SELECT e_name, e_id FROM <Table_Name>;
MYSQL Functions
MySQL has many built-in functions. Some of them are as: COUNT( ),
SUM( ), AVG( ), MAX( ), MIN( )
COUNT( ) – The COUNT() function returns the number of rows that
matches a specified criterion.
SELECT COUNT(*) FROM table_name WHERE condition;
SELECT COUNT(column_name) FROM table_name WHERE condition;
SUM( ) – The SUM() function returns the total sum of a numeric column.
SELECT SUM(column_name) FROM table_name WHERE condition;
AVG( ) – The AVG() function returns the average value of a numeric
column.
SELECT AVG(column_name) FROM table_name WHERE condition;
MAX( ) – The MAX() function returns the largest value of the selected
column.
SELECT MAX(column_name) FROM table_name WHERE condition;
MIN( ) – The MIN() function returns the smallest value of the selected
column.
SELECT MIN(column_name) FROM table_name WHERE condition;
SQL Queries Examples