Student database using MySQL Part 3

EXAMPLE FOR MYSQL CLAUSE

        Will have an example for MySQL clauses.


WHERE CLAUSE:

    SELECT * FROM Students WHERE department=3;

    Query filter the records from the Students table based on the department.



ORDER BY:

    SELECT * FROM Students ORDER BY district DESC;

    Sort the result set in descending order.


LIMIT:

    SELECT * FROM Students LIMIT 2;

    This query returns only 2 records from the Students table.


GROUP BY:

    SELECT COUNT(name), department FROM Students GROUP BY department;

    Query group the rows that have the same department.

    It returns the count of the students in the same department. 

    GROUP BY groups the records based on the department and it counts the name of the student based on the grouped department data.




HAVING:

    SELECT COUNT(name), department FROM Students GROUP BY department HAVING COUNT(name) > 1;

    Having clause is used with GROUP BY.

    It returns the record where the condition is TRUE.

    This query groups the rows based on the department and returns the record from the Students table where the count is greater than 1.




 Thanks for choosing our blog 😊. 
Will discuss an example of MySQL operators in the next part. -  Part-4


Tutorial Topics for examples:
Database Creation -  Part-1
Table Modifications  -  Part-2
Clauses   - Part-3
Operators  - Part-4
Joins  - Part-5

Comments

Popular posts from this blog

MySQL Tutorial Part 1

Pandas DataFrame empty

Introduction to Java