Write a query to display the subject_name and subject_code of the subjects handled by the staff named 'Lakshmi'. Display the records sorted in ascending order based on subject_name.Note:1. Display only the subject_name and subject_code of the subjects handled by the staff named 'Lakshmi'.2. Use Joins. Tables involved are subject and staff3. Order by is mandatory.
Question
Write a query to display the subject_name and subject_code of the subjects handled by the staff named 'Lakshmi'. Display the records sorted in ascending order based on subject_name.Note:1. Display only the subject_name and subject_code of the subjects handled by the staff named 'Lakshmi'.2. Use Joins. Tables involved are subject and staff3. Order by is mandatory.
Solution
Here is the SQL query you asked for:
SELECT subject.subject_name, subject.subject_code
FROM subject
JOIN staff ON subject.staff_id = staff.staff_id
WHERE staff.staff_name = 'Lakshmi'
ORDER BY subject.subject_name ASC;
Here is the step by step explanation:
-
SELECT subject.subject_name, subject.subject_code: This part of the query is used to select the columnssubject_nameandsubject_codefrom thesubjecttable. -
FROM subject: This part of the query specifies the table from which we want to select the data, which is thesubjecttable. -
JOIN staff ON subject.staff_id = staff.staff_id: This part of the query is used to join thesubjecttable with thestafftable. The join is made on the condition that thestaff_idin thesubjecttable matches thestaff_idin thestafftable. -
WHERE staff.staff_name = 'Lakshmi': This part of the query is a condition that filters the records such that only the subjects handled by the staff named 'Lakshmi' are selected. -
ORDER BY subject.subject_name ASC: This part of the query is used to sort the resulting records in ascending order based on thesubject_name.
Similar Questions
Write a query to retrieve the names of all employees and sort them in ascending order.Table: EmployeeInput records:Input format :The input table is already created, and records are already prepopulated, as mentioned in the problem statement.Output format :The output displays the names of all employees in ascending order as shown below.NameAngelMarkMathewSteveRefer to the sample output for the column headers.
Choose the query to display names of the department in the college ordered in department_name in ascending order.select department_name from Department order by department_name asc;select department_name from Department order by name asc;select name from Department order by name;None of the listed optionsReview Answer
Write a query to display the ename of employees working in 'HR' department and who draw an annual salary greater than 1000000. [Consider employees who work in multiple departments too]. Display the records sorted in ascending order based on employee ename.Note:1. Display all the ename of employees working in 'HR' department and having annual salary greater than 1000000.2. Use Joins. Tables involved are employee, works and department3. Order by is mandatory.
Write a MySQL statement to sort the students in descending order of the last name
SELECT nameFROM instructorWHERE dept name = ’Physics’ORDER BY name;By default, the order by clause lists items in ______ order.AnyAscendingSameDescending
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.