Page 51 - Modular_V2.0_SQL_Flipbook
P. 51
5 ADVANCED FEATURES
OF MYSQL
Your Aim
to learn about:
Subqueries Joins
Views Index
This chapter covers important MySQL features: subqueries, joins, views, and indexes. These concepts
help in managing and retrieving data efficiently from databases. Understanding these features will
improve your ability to write complex queries and work with multiple tables. This knowledge is
essential for developing better database applications.
SUBQUERIES
A subquery can be defined as a query within another query. It can be embedded within various
clauses of the main query, such as the WHERE, HAVING, or FROM clause. A subquery helps retrieve
data that will be used by the main query.
Syntax:
SELECT column1, column2
FROM table1
WHERE column1 = (SELECT column1 FROM table2 WHERE condition);
For example, consider the following Table - STUDENTS
Minimum value
Table-STUDENTS of result set
Stu_id Stu_name Subject_group DOB Age
101 Rahim Arts 2000-10-10 22
102 Raja Commerce 1999-01-08 23
103 Rita Arts 2001-03-12 21
104 Rani Science 2002-04-01 20
105 Riya Science 2003-05-18 24
SELECT * FROM STUDENTS WHERE Age = (SELECT MIN(Age) FROM STUDENTS);
The above query will extract the records that have the minimum value in the given dataset and
display the details of those records that meet the criteria.
49
Advanced Features of MySQL

