MySQL Practice Set for Class 12 Students
MySQL Practice Set for Class 12 Students
To list all student names in alphabetical order, you use the SQL query: SELECT Name FROM Students ORDER BY Name ASC.
The approach in SQL to select the top three students by marks involves using ORDER BY Marks DESC and LIMIT 3: SELECT Name, Marks FROM Students ORDER BY Marks DESC LIMIT 3. This is relevant in data analysis for identifying top performers, enabling targeted interventions and rewarding academic excellence.
The GROUP BY clause in SQL is significant for aggregating data into summary rows, typically used with aggregate functions like COUNT. In the context of displaying the total number of students per class, it allows grouping of records by the 'Class' field and calculating the count of students within each class.
The 'Subjects' table complements the 'Students' table by allowing the association of subjects with student records through the RollNo field. This design, exemplified by the common RollNo field, supports normalization by separating related data into multiple tables, reducing redundancy and inconsistencies, and facilitating efficient data retrieval through JOIN operations.
Using SQL's ORDER BY clause for data presentation, such as ordering student names or marks, directly impacts how data is organized and perceived. It improves readability, allowing clear insights like ranking or grouping. However, it also introduces complexity in query execution and may affect performance with large datasets, necessitating indexing or query optimization strategies.
You can create a table named 'Students' using the SQL command: CREATE TABLE Students (RollNo INT, Name VARCHAR(30), Class INT, Marks INT)
SQL can delete records using the query: DELETE FROM Students WHERE Marks < 40. This operation is necessary for data management, ensuring that only relevant and meaningful records are retained in the database. It helps maintain data integrity by removing poorly performing entries and potentially facilitating performance optimization by reducing table size.
You can find the highest and lowest marks using the SQL query: SELECT MAX(Marks) AS Highest, MIN(Marks) AS Lowest FROM Students. This uses aggregate functions MAX and MIN to determine the highest and lowest values, respectively.
To update a student's marks in SQL where the RollNo is 102, you use the query: UPDATE Students SET Marks = 90 WHERE RollNo = 102. This changes the marks field for the student with the specified RollNo.
An INNER JOIN in SQL combines rows from two tables based on a related column, returning only matching rows from both tables. For example, to display student names with their subject names using INNER JOIN, the query would be: SELECT Students.Name, Subjects.SubjectName FROM Students INNER JOIN Subjects ON Students.RollNo = Subjects.RollNo. This matches records where RollNo in both tables are the same.