SH Ut Os H: Youtube
SH Ut Os H: Youtube
👉
YouTube
https://youtube.com/@codewithashutosh247?si=rXike59WnLhUEUkL
to
hu
👉
Whatsapp Group -
https://chat.whatsapp.com/Iy2Ag6hE35WENehlmNcctV
As
👉
Telegram Group -
ith
https://t.me/+3jqmwqzNp3xlMTZl
👉
Git & GitHub -
W
https://github.com/AshutoshG1?tab=repositories
e
od
C
MySQL
Q. What is a Database ?
● A database is a structured collection of data stored electronically,
sh
often managed by a Database Management System (DBMS).
● It allows for efficient data retrieval, manipulation, and management.
to
Q. What is Data ?
hu
● Data refers to raw facts and figures that are collected and stored,
which can be processed to generate meaningful information.
As
● It can be in various forms, such as numbers, text, or multimedia.
ith
Q. What is DBMS ?
● A Database Management System (DBMS) is software that facilitates
W
Q. What is RDBMS ?
● A Relational Database Management System (RDBMS) is a type of
DBMS that organizes data into tables with rows and columns,
C
sh
● It can be null or duplicate.
to
● The primary key constraint uniquely identifies each record in a table.
● It should be unique and not null.
hu
Q. What is the candidate key? As
● A candidate key is a minimal set of columns that can uniquely identify
a record in a table.
● There can be multiple candidate keys, but only one is chosen as the
ith
primary key.
sh
to
👉 https://chat.whatsapp.com/Iy2Ag6hE35WENehlmNcctV
hu
As
Q. SQL vs MySQL vs NoSQL ?
ith
sh
○ Second Normal Form (2NF): Achieved when the table is in
1NF and all non-key attributes are fully functionally dependent
on the entire primary key.
to
○ Third Normal Form (3NF): Achieved when the table is in 2NF
and all attributes are only dependent on the primary key, not on
hu
other non-key attributes.
○ Boyce-Codd Normal Form (BCNF): A stronger version of 3NF
where every determinant is a candidate key.
As
○ Fourth Normal Form (4NF): Eliminates multivalued
dependencies by ensuring that no table contains two or more
independent multi-valued facts about an entity.
ith
Types of Relationships:
od
sh
to
Q. What is Commit ?
● To permanently save all the changes made during the current
hu
transaction to the database.
Q. What is rollback ?
As
● It is used to undo all changes made during the current transaction .
● The having clause was added to SQL because the where keyword
cannot be used with aggregate functions.
W
Q. What is GroupBy ?
● It is used to group the rows that have the same values in specified
e
column.
od
Q. What is Order By ?
● It is used to sort the result set in ascending or descending order
C
sh
● DDL (Data Definition Language): Defines and manages database
structure (e.g., CREATE, ALTER, DROP).
to
● DML (Data Manipulation Language): Handles data manipulation
(e.g., SELECT, INSERT, UPDATE, DELETE).
hu
● DQL (Data Query Language): Queries data from the database (e.g.,
SELECT).
● DCL (Data Control Language): Manages access permissions (e.g.,
As
GRANT, REVOKE).
● TCL (Transaction Control Language): Manages transactions (e.g.,
COMMIT, ROLLBACK, SAVEPOINT).
ith
W
Q. What is Indexing ?
● In mysql , indexing improves the speed of the data retrieval
e
sh
to
hu
As
Query Set - 1
ith
W
e
od
C
C
od
e
W
ith
As
hu
to
sh
Q1. Write a query to fetch the EmpFname from the EmployeeInfo table in
upper case and use the ALIAS name as EmpName.
sh
SELECT COUNT(*) FROM EmployeeInfo WHERE Department = 'HR';
to
Q3. Write a query to get the current date and time .
hu
SELECT NOW();
As
Write a query to get the current date
SELECT CURDATE();
ith
Q4. Write a query to retrieve the first four characters of EmpLname from
W
Q5. Write a query to fetch only the place name(string before brackets) from
od
Q7. Write a query to find all the employees whose salary is between 50000
to 100000.
sh
SELECT * FROM EmployeePosition WHERE Salary BETWEEN '50000'
AND '100000';
to
Q8. Write a query to find the names of employees that begin with ‘S’
hu
SELECT * FROM EmployeeInfo WHERE EmpFname LIKE 'S%';
As
Q9. Write a query to fetch top N records.
SELECT *
FROM employeeposition
ith
column as “FullName”. The first name and the last name must be
separated with space.
od
C
Q12. Write a query to fetch all the records from the EmployeeInfo table
ordered by EmpLname in descending order and Department in the
ascending order.
sh
SELECT * FROM EmployeeInfo ORDER BY EmpFname desc, Department
asc;
to
Q13. Write a query to fetch details of employees whose EmpLname ends
hu
with an alphabet ‘A’ and contains five alphabets.
As
SELECT * FROM EmployeeInfo WHERE EmpLname LIKE '____a';
table.
W
Q16. Write a query to fetch all employees who also hold the managerial
position.
sh
ORDER BY EmpDeptCount ASC;
to
Q18. Write a query to calculate the even and odd records from a table.
To retrieve the even records from a table, you have to use the MOD()
hu
function as follows:
As
Q19. Write a SQL query to retrieve employee details from EmployeeInfo
table who have a date of joining in the EmployeePosition table.
ith
WHERE EXISTS
(SELECT * FROM EmployeePosition P WHERE E.EmpId = P.EmpId);
e
Q20. Write a query to retrieve two minimum and maximum salaries from
the EmployeePosition table.
od
sh
to
SELECT DISTINCT Salary
FROM EmployeePosition E1
hu
WHERE 2 >= (
SELECT COUNT(DISTINCT Salary)
FROM EmployeePosition E2 As
WHERE E1.Salary <= E2.Salary
)
ORDER BY E1.Salary DESC;
ith
Q21. Write a query to find the Nth highest salary from the table without
W
SELECT Salary
FROM EmployeePosition E1
od
WHERE N-1 = (
SELECT COUNT( DISTINCT ( E2.Salary ) )
C
FROM EmployeePosition E2
WHERE E2.Salary > E1.Salary );
Q23. Write a query to retrieve the list of employees working in the same
department.
sh
SELECT DISTINCT E.EmpID, E.EmpFname, E.Department
to
FROM EmployeeInfo E
JOIN EmployeeInfo E1 ON E.Department = E1.Department
hu
WHERE E.EmpID != E1.EmpID;
As
Q24. Write a query to retrieve the last 3 records from the EmployeeInfo
table.
ith
Q25. Write a query to find the third-highest salary from the EmpPosition
table.
od
C
Q26. Write a query to display the first and the last record from the
EmployeeInfo table.
To display the first record from the EmployeeInfo table, you can write a
query as follows:
SELECT * FROM EmployeeInfo WHERE EmpID = (SELECT MIN(EmpID)
FROM EmployeeInfo);
To display the last record from the EmployeeInfo table, you can write a
query as follows:
sh
SELECT * FROM EmployeeInfo WHERE EmpID = (SELECT MAX(EmpID)
FROM EmployeeInfo);
to
Q27. Write a query to add email validation to your database
hu
As
Q28. Write a query to retrieve Departments who have less than 2
employees working in it.
FROM EmployeeInfo
GROUP BY DEPARTMENT
W
Q29. Write a query to retrieve EmpPostion along with total salaries paid for
each of them.
od
EmpPosition;
Q30. Write a query to fetch 50% records from the EmployeeInfo table.
SELECT *
FROM employeeinfo
ORDER BY EmpID DESC
sh
LIMIT 5;
to
hu
Q32. Write a SQL query that will provide you with the 10th-highest
employee salary from an Employee table.
As
SELECT salary
FROM (
ith
FROM employeeposition
) AS ranked_salary
WHERE row_num = 10;
e
od
C
sh
SQL Query Interview Questions and Answers
to
We have created three sample tables: Student Table, Program Table,
and Scholarship Table. We will be using these tables to perform various
hu
query operations.
Student Table
As
ith
Computer
201 Shivansh Mahajan 8.79 2021-09-01 09:30:00
Science
e
od
C
Mathematic
202 Umesh Sharma 8.44 2021-09-01 08:30:00
s
203 Rakesh Kumar 5.60 2021-09-01 10:00:00 Biology
sh
to
205 Kush Kumar 7.85 2021-09-01 08:30:00 Physics
hu
206 Prem Chopra
As9.56 2021-09-01 09:24:00 History
ith
Mathematic
208 Navleen Kaur 7.00 2021-09-01 06:30:00
s
od
C
Program Table
sh
to
208 Mathematics 2021-09-01 00:00:00
hu
205 Physics
As 2021-09-01 00:00:00
ith
Scholarship Table
sh
STUDENT_REF_ID SCHOLARSHIP_AMOUNT SCHOLARSHIP_DATE
to
hu
201 5000 2021-10-15 00:00:00
As
202 4500 2022-08-18 00:00:00
ith
W
Let us start by taking a look at some of the most asked SQL Query
interview questions:
1. Write a SQL query to fetch “FIRST_NAME” from the Student table in
upper case and use ALIAS name as STUDENT_NAME.
Output:
SHIVANSH
sh
UMESH
RAKESH
to
RADHA
KUSH
hu
PREM
PANKAJ As
NAVLEEN
Student table.
or
SELECT MAJOR FROM STUDENT GROUP BY(MAJOR);
e
Output:
od
Computer Science
Mathematics
C
Biology
Chemistry
Physics
History
English
3. Write a SQL query to print the first 3 characters of FIRST_NAME
from Student table.
Output:
Shi
sh
Ume
Rak
to
Rad
Kus
hu
Pre
Pan As
Nav
4. Write a SQL query to find the position of alphabet (‘a’) int the first
ith
'Shivansh';
Output:
e
5
od
5. Write a SQL query that fetches the unique values of MAJOR Subjects
from Student table and print its length.
C
Output:
MAJOR LENGTH(MAJOR)
Computer Science 16
sh
to
Mathematics 11
hu
As
Biology 7
ith
Chemistry 9
W
e
od
Physics 7
C
History 7
English 7
6. Write a SQL query to print FIRST_NAME from the Student table after
replacing ‘a’ with ‘A’.
sh
SELECT REPLACE(FIRST_NAME, 'a', 'A') FROM Student;
to
Output:
hu
ShivAnsh
Umesh
RAkesh
As
RAdhA
Kush
ith
Prem
PAnkAj
W
NAvleen
Output:
Shivansh Mahajan
Umesh Sharma
Rakesh Kumar
Radha Sharma
Kush Kumar
Prem Chopra
Pankaj Vats
Navleen Kaur
8. Write a SQL query to print all Student details from Student table
order by FIRST_NAME Ascending and MAJOR Subject descending .
sh
SELECT * FROM Student ORDER BY FIRST_NAME , MAJOR DESC;
to
Output:
hu
STUDENT FIRST_NA LAST_NA GP ENROLLMENT_
MAJOR
_ID ME ME A DATE
As
ith
7.8 2021-09-01
205 Kush Kumar Physics
5 08:30:00
W
e
od
2021-09-01 Mathem
208 Navleen Kaur 7
06:30:00 atics
C
9.7 2021-09-01
207 Pankaj Vats English
8 02:30:00
sh
9.5 2021-09-01
206 Prem Chopra History
6 09:24:00
to
hu
2021-09-01 Chemistr
204 Radha Sharma 9.2
12:45:00 y
As
ith
2021-09-01
203 Rakesh Kumar 5.6 Biology
10:00:00
W
e
od
sh
FIRST_NAME as ‘Prem’ and ‘Shivansh’ from Student table.
to
SELECT * from Student WHERE FIRST_NAME IN ('Prem' , 'Shivansh');
Output:
hu
STUDENT FIRST_NA LAST_NA GP ENROLLMENT_D MAJO
As
_ID ME ME A ATE R
ith
Compu
W
Output:
sh
STUDENT FIRST_NA LAST_NA GP ENROLLMENT_
MAJOR
_ID ME ME A DATE
to
hu
8.4 2021-09-01 Mathem
202 Umesh Sharma
As
4 08:30:00 atics
ith
2021-09-01
W
2021-09-01 Chemistr
204 Radha Sharma 9.2
12:45:00 y
C
7.8 2021-09-01
205 Kush Kumar Physics
5 08:30:00
sh
9.7 2021-09-01
207 Pankaj Vats English
8 02:30:00
to
hu
2021-09-01 Mathem
208 Navleen Kaur 7
06:30:00 atics
As
ith
Output:
e
od
sh
FIRST_NAME ends with ‘a’ and contains six alphabets.
to
SELECT * FROM Student WHERE FIRST_NAME LIKE '_____a';
hu
13. Write an SQL query to print details of the Students whose GPA lies
between 9.00 and 9.99. As
SELECT * FROM Student WHERE GPA BETWEEN 9.00 AND 9.99;
Output:
ith
_ID ME ME A ATE R
e
od
2021-09-01 Chemis
204 Radha Sharma 9.2
12:45:00 try
C
9.5 2021-09-01
206 Prem Chopra History
6 09:24:00
sh
9.7 2021-09-01
207 Pankaj Vats English
8 02:30:00
to
hu
14. Write an SQL query to fetch the count of Students having Major
Subject ‘Computer Science’. As
SELECT Major, COUNT(*) as TOTAL_COUNT FROM Student WHERE MAJOR =
'Computer Science';
ith
Output:
W
MAJOR TOTAL_COUNT
e
od
Computer Science 1
C
15. Write an SQL query to fetch Students full names with GPA >= 8.5
and <= 9.5.
SELECT CONCAT(FIRST_NAME, ' ', LAST_NAME) AS FULL_NAME FROM
Student WHERE GPA BETWEEN 8.5 and 9.5;
Output:
Shivansh Mahajan
Radha Sharma
16. Write an SQL query to fetch the no. of Students for each MAJOR
sh
subject in the descending order.
to
SELECT MAJOR, COUNT(MAJOR) from Student group by MAJOR order by
COUNT(MAJOR) DESC;
hu
Output:
As
MAJOR COUNT(MAJOR)
ith
Mathematics 2
W
e
Physics 1
od
C
History 1
English 1
Computer Science 1
sh
to
Chemistry 1
hu
Biology 1
As
ith
SELECT
Student.FIRST_NAME,
e
Student.LAST_NAME,
od
Scholarship.SCHOLARSHIP_AMOUNT,
Scholarship.SCHOLARSHIP_DATE
C
FROM
Student
INNER JOIN
Scholarship ON Student.STUDENT_ID =
Scholarship.STUDENT_REF_ID;
Output:
sh
2021-10-15
Shivansh Mahajan 5000
00:00:00
to
hu
2022-08-18
Umesh Sharma 4500
As 00:00:00
ith
2022-01-25
Rakesh Kumar 3000
00:00:00
W
e
2021-10-15
od
18. Write an SQL query to show only odd rows from Student table.
Output:
STUDENT FIRST_NA LAST_NA GP ENROLLMENT_D MAJO
_ID ME ME A ATE R
sh
Compu
8.7 2021-09-01 ter
201 Shivansh Mahajan
9 09:30:00 Scienc
to
e
hu
As 2021-09-01 Biolog
203 Rakesh Kumar 5.6
10:00:00 y
ith
19. Write an SQL query to show only even rows from Student table.
sh
8.4 2021-09-01 Mathem
202 Umesh Sharma
to
4 08:30:00 atics
hu
2021-09-01 Chemistr
204 Radha Sharma
As 9.2
12:45:00 y
ith
9.5 2021-09-01
206 Prem Chopra History
W
6 09:24:00
e
od
2021-09-01 Mathem
208 Navleen Kaur 7
06:30:00 atics
C
20. List all students and their scholarship amounts if they have received
any. If a student has not received a scholarship, display NULL for the
scholarship details.
SELECT
Student.FIRST_NAME,
Student.LAST_NAME,
Scholarship.SCHOLARSHIP_AMOUNT,
Scholarship.SCHOLARSHIP_DATE
FROM
sh
Student
LEFT JOIN
to
Scholarship ON Student.STUDENT_ID =
Scholarship.STUDENT_REF_ID;
hu
21. Write an SQL query to show the top n (say 5) records of Student
table order by descending GPA.
As
SELECT * from Student ORDER BY GPA DESC LIMIT 5;
Output:
ith
MAJOR
_ID ME ME A DATE
e
od
9.7 2021-09-01
207 Pankaj Vats English
8 02:30:00
C
9.5 2021-09-01
206 Prem Chopra History
6 09:24:00
2021-09-01 Chemistr
sh
204 Radha Sharma 9.2
12:45:00 y
to
hu
8.7 2021-09-01 Compute
201 Shivansh Mahajan
9
As 09:30:00 r Science
22. Write an SQL query to determine the nth (say n=5) highest GPA
e
from a table.
od
Output:
C
23. Write an SQL query to determine the 5th highest GPA without
sh
using LIMIT keyword.
to
SELECT * FROM Student s1
WHERE 4 = (
hu
SELECT COUNT(DISTINCT (s2.GPA))
FROM Student s2
As
WHERE s2.GPA >= s1.GPA
);
ith
Output:
W
Compu
C
25. Write an SQL query to show the second highest GPA from a
Student table using sub-query.
sh
SELECT MAX(GPA) FROM Student
WHERE GPA NOT IN(SELECT MAX(GPA) FROM Student);
to
Output:
hu
9.56
26. Write an SQL query to show one row twice in results from a table.
As
SELECT * FROM Student
UNION ALL
ith
27. Write an SQL query to list STUDENT_ID who does not get
W
Scholarship.
e
Output:
C
204
205
206
207
208
28. Write an SQL query to fetch the first 50% records from a table.
29. Write an SQL query to fetch the MAJOR subject that have less than
4 people in it.
sh
SELECT MAJOR, COUNT(MAJOR) AS MAJOR_COUNT FROM Student GROUP BY
MAJOR HAVING COUNT(MAJOR) < 4;
to
Output:
hu
MAJOR MAJOR_COUNT As
Biology 1
ith
W
Chemistry 1
e
od
Computer Science 1
C
English 1
History 1
Mathematics 2
sh
to
Physics 1
hu
30. Write an SQL query to show all MAJOR subject along with the
number of people in there.
As
SELECT MAJOR, COUNT(MAJOR) AS ALL_MAJOR FROM Student GROUP BY
ith
MAJOR;
Output:
W
MAJOR ALL_MAJOR
e
od
Biology 1
C
Chemistry 1
Computer Science 1
English 1
sh
to
History 1
hu
Mathematics 2
As
ith
Physics 1
W
31. Write an SQL query to show the last record from a table.
e
FROM STUDENT);
Output:
C
sh
SELECT * FROM Student WHERE STUDENT_ID = (SELECT MIN(STUDENT_ID)
FROM Student);
to
Output:
hu
STUDENT FIRST_NA LAST_NA
As GP ENROLLMENT_D MAJO
_ID ME ME A ATE R
ith
Compu
8.7 2021-09-01 ter
W
33. Write an SQL query to fetch the last five records from a table.
C
SELECT *
FROM (
SELECT *
FROM Student
ORDER BY STUDENT_ID DESC
LIMIT 5
) AS subquery
ORDER BY STUDENT_ID;
Output:
sh
MAJOR
_ID ME ME A DATE
to
hu
2021-09-01 Chemistr
204 Radha Sharma 9.2
As 12:45:00 y
7.8 2021-09-01
ith
9.5 2021-09-01
e
9.7 2021-09-01
207 Pankaj Vats English
8 02:30:00
2021-09-01 Mathem
208 Navleen Kaur 7
06:30:00 atics
34. Write an SQL query to fetch three max GPA from a table using
sh
co-related subquery.
to
WHERE 3 >= (SELECT COUNT(DISTINCT GPA) FROM Student S2 WHERE
S1.GPA <= S2.GPA) ORDER BY S1.GPA DESC;
hu
Output:
9.78
As
9.56
9.2
ith
35. Write an SQL query to fetch three min GPA from a table using
co-related subquery.
W
Output:
5.6
C
7
7.85
36. Write an SQL query to fetch nth max GPA from a table.
37. Write an SQL query to fetch MAJOR subjects along with the max
GPA in each of these MAJOR subjects.
Output:
sh
to
MAJOR MAXGPA
hu
Biology 5.6
As
ith
Chemistry 9.2
W
English 9.78
C
History 9.56
Mathematics 8.44
Physics 7.85
sh
38. Write an SQL query to fetch the names of Students who has highest
to
GPA.
hu
SELECT FIRST_NAME, GPA FROM Student WHERE GPA = (SELECT MAX(GPA)
FROM Student); As
Output:
ith
FIRST_NAME GPA
W
Pankaj 9.78
e
od
39. Write an SQL query to show the current date and time.
C
41. Write an SQL query to update the GPA of all the students in
sh
‘Computer Science’ MAJOR subject to 7.5.
to
42. Write an SQL query to find the average GPA for each major.
hu
SELECT MAJOR, AVG(GPA) AS AVERAGE_GPA FROM Student GROUP BY
MAJOR;
As
Output:
ith
MAJOR AVERAGE_GPA
W
Biology 5.6
e
od
Chemistry 9.2
C
Computer Science 4
English 9.78
History 9.56
sh
to
Mathematics 7.72
hu
Physics 7.85
As
ith
43. Write an SQL query to show the top 3 students with the highest
GPA.
W
Output:
e
od
9.5 2021-09-01
sh
206 Prem Chopra History
6 09:24:00
to
hu
2021-09-01 Chemis
204 Radha Sharma 9.2
As 12:45:00 try
44. Write an SQL query to find the number of students in each major
ith
Output:
e
od
MAJOR HIGH_GPA_COUNT
C
Biology 1
Chemistry 1
Computer Science 1
sh
to
English 1
hu
History 1
As
ith
Mathematics 2
W
Physics 1
e
od
45. Write an SQL query to find the students who have the same GPA as
C
‘Shivansh Mahajan’.
SELECT * FROM Student WHERE GPA = (SELECT GPA FROM Student WHERE
FIRST_NAME = 'Shivansh'
AND LAST_NAME = 'Mahajan');
Output:
STUDENT FIRST_NA LAST_NA GP ENROLLMENT_D MAJO
_ID ME ME A ATE R
Compu
sh
2021-09-01 ter
201 Shivansh Mahajan 4
09:30:00 Scienc
to
e
hu
As
ith
W
Indexing in MySQL
e
od
C
Indexes are used to retrieve data from the database more quickly than
otherwise. The users cannot see the indexes, they are just used to speed up
searches/queries.
Note: Updating a table with indexes takes more time than updating a table without
(because the indexes also need an update). So, only create indexes on columns that will
be frequently searched against.
sh
CREATE INDEX index_name
to
ON table_name (column1, column2, ...);
hu
CREATE UNIQUE INDEX Syntax As
Creates a unique index on a table. Duplicate values are not allowed:
ON Persons (LastName);
If you want to create an index on a combination of columns, you can list the
column names within the parentheses, separated by commas:
sh
DROP INDEX Statement
to
The DROP INDEX statement is used to delete an index in a table.
hu
ALTER TABLE table_name
As
DROP INDEX index_name;
ith
An index is a data structure that allows us to add indexes in the existing table. It
enables you to improve the faster retrieval of records on a database table. It
e
creates an entry for each value of the indexed columns. We use it to quickly find
the record without searching each row in a database table whenever the table is
od
accessed. We can create an index by using one or more columns of the table for
efficient access to the records.
C
When a table is created with a primary key or unique key, it automatically creates
a special index named PRIMARY. We called this index as a clustered index. All
indexes other than PRIMARY indexes are known as a non-clustered index or
secondary index.
To find the name and contact of the user from table contactbooks, generally, we
used to execute the following query:
sh
SELECT mobile_number FROM contactbooks WHERE first_name =
'Martin' AND last_name = 'Taybu';
to
This query is very simple and easy. Although it finds the phone number and
name of the user fast, the database searches entire rows of the table until it will
hu
not find the rows that you want. Assume, the contactbooks table contains
millions of rows, then, without an index, the data retrieval takes a lot of time to
find the result. In that case, the database indexing plays an important role in
As
returning the desired result and improves the overall performance of the query.
following statement creates a table with an index that contains two columns col2
and col3.
W
col4 VARCHAR(20),
od
INDEX (col2,col3)
);
If we want to add index in table, we will use the CREATE INDEX statement as
C
follows:
Example
sh
In this example, we are going to create a table student and perform the CREATE
INDEX statement on that table.
to
hu
As
ith
Now, execute the following statement to return the result of the student whose
class is CS branch:
W
In the above table, we can see the four rows that are indicating the students
whose class is the CS branch.
If you want to see how MySQL performs this query internally, execute the
following statement:
sh
to
Now, let us create an index for a class column using the following statement.
hu
mysql> CREATE INDEX class ON student (class);
After executing the above statement, the index is created successfully. Now, run
the below statement to see how MySQL internally performs this query.
As
mysql> EXPLAIN SELECT studentid, firstname, lastname FROM student
WHERE class = 'CS';
ith
In this output, MySQL finds four rows from the class index without scanning the
whole table. Hence, it increases the speed of retrieval of records on a database
e
table.
od
If you want to show the indexes of a table, execute the following statement:
hu
https://youtube.com/@codewithashutosh247?si=rXike59WnLhUEUkL
As
👉
Whatsapp Group -
https://chat.whatsapp.com/Iy2Ag6hE35WENehlmNcctV
ith
👉
Telegram Group -
W
https://t.me/+3jqmwqzNp3xlMTZl
👉
Git & GitHub -
e
https://github.com/AshutoshG1?tab=repositories
od
C