MySQL Query
MySQL Query
MySQL query
Syntax :
SELECT * FROM Table_name;
1
SELECT Column
To get data from specific column(s) and not everything, or you simply
want to just state the field name.
Syntax :
SELECT Column_name
FROM Table_name;
2
WHERE Clause
WHERE clause is used as a condition for specific records that match the
condition(s) as the result.
Syntax :
SELECT *
FROM Table_name
WHERE EmployeeID = 1008 ;
3
CREATE Table
This query can be used to generate a new table with your rpreferred
choice of columns. When adding column names be sure to specify their
data type.
Syntax :
CREATE TABLE Table_name(
Id INT,
Department VARCHAR(55),
);
4
INSERT INTO
Query to insert values into one or more rows of new records into a table.
When writing an INSERT INTO query, the VALUES command must be a
part of the complete statement.
Syntax :
INSERT INTO EmployeeInfo (ID, Department)
VALUES
(1002, HR , 46)
(1004, IT , 39);
5
UPDATE
This keyword is used to change one or more existing columns in a table.
Using this query will update table records with new data based on some
condition. Following the UPDATE command, use the keyword SET to always
specify which column(s) you choose to modify, then state exactly WHERE
you need the updated data applied to.
Syntax :
UPDATE Existing_table_name
SET Age = 22
WHERE Id = 1008;
6
DELETE FROM
To remove records from a table based on one or multiple conditions you
would need to use the DELETE FROM statement. Use WHERE condition
to determine exactly where you need the updated data applied to.
Syntax :
DELETE FROM Existing_table_name
WHERE Name = ‘Sunny’;
7
GROUP BY & HAVING Clause
Using the GROUP BY clause will group together the result-set by one or
more columns. The HAVING keyword is used to filter that result set.
Syntax :
SELECT COUNT(Age), Id
FROM Existing_table_name
GROUP BY Id
HAVING COUNT(Age) > 25;
8
Aggregate Functions (COUNT)
There are three extremely common aggregate functions that allow data
from a table to be interpreted or run calculations.
Syntax :
SELECT
COUNT(Department)
FROM Existing_table_name;
9
Aggregate Functions (AVG)
There are three extremely common aggregate functions that allow data
from a table to be interpreted or run calculations.
Syntax :
SELECT AVG(Age)
FROM Existing_table_name;
9
Aggregate Functions (SUM)
There are three extremely common aggregate functions that allow data
from a table to be interpreted or run calculations.
Syntax :
SELECT SUM(Age)
FROM Existing_table_name;
9
JOINS
Joins are used to bring together rows from at least two tables, based on a
related column between the tables. The most common practice joins are
INNER, FULL and LEFT.
INNER JOIN – combines the rows from different tables if the join condition
is true.
FULL JOIN – returns all rows when there is a match in left or right table
records.
LEFT JOIN – retrieves all rows from the left table and the matching records
from the right table.
8
INNER JOIN
Syntax :
8
FULL JOIN
Syntax :
SELECT *
FROM Student
FULL JOIN StudentInfo
ON Student.Id = StudentInfo.Info_Id;
8
LEFT JOIN
Syntax :
8
Thanks For Stopping By