MySQL clauses tutorial point; Through this tutorial, we will demonstrate about MySQL clauses like DISTINCT, FROM, GROUP BY, ORDER BY, HAVING, WHERE. And we will learn about MySQL clauses with simple and easy syntax & examples.
You should also learn MySQL date and time functions, which are used to MySQL clauses.
Types of clauses in MySQL
Let’s see following MySQL clauses with an examples:
- WHERE Clause MySQL
- DISTINCT Clause MySQL
- FROM Clause MySQL
- ORDER BY Clause MySQL
- GROUP BY Clause MySQL
- HAVING Clause MySQL
WHERE Clause MySQL
In MySQL WHERE Clause commonly used with SELECT statement, INSERT INTO statement, UPDATE statment and DELETE statement. Because it filter the record from database table.
Syntax
WHERE conditions;
WHERE Clause MySQL Example
SELECT * FROM users WHERE email = 'tutsmake@gmail.com';
The above statement selects all the records from the database table users, where the value of the email column is equal to tutsmake@gmail.com.
Where Clause with AND
SELECT * FROM users WHERE first_name = 'tut' AND id < 1000;
The above statement selects all the records from the database table users, where the value of the name column is equal to tuts and it’s id less than 1000.
MySQL DISTINCT Clause
In MySQL DISTINCT Clause can be used within an MySQL statement to remove duplicate rows from the databse table and retrive only the unique data.
Syntax
SELECT DISTINCT column1,column2 ….columnN FROM tables [WHERE conditions];
DISTINCT Clause MySQL Example
SELECT DISTINCT name FROM users;
This above query using the DISTINCT keyword to removed the duplicates data. Therefore, it will contain a unique value.
MySQL FROM Clause
The MySQL FROM Clause can be used to select some records from the database table. Using the JOIN Clause, it can also be used to obtain records from several database tables.
Syntax
FROM table1 [ { INNER JOIN | LEFT [OUTER] JOIN | RIGHT [OUTER] JOIN } table2 ON table1.column1 = table2.column1 ]