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.
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.
Solution
Assuming that you are using a SQL database and you have a table named 'Subjects' with columns 'subject_name', 'subject_code' and 'staff_name', and another table named 'Staff' with columns 'staff_name', you can use the following query:
SELECT Subjects.subject_name, Subjects.subject_code
FROM Subjects
INNER JOIN Staff ON Subjects.staff_name = Staff.staff_name
WHERE Staff.staff_name = 'Lakshmi'
ORDER BY Subjects.subject_name ASC;
Here's the step by step explanation:
-
SELECT Subjects.subject_name, Subjects.subject_code: This line is selecting the columns 'subject_name' and 'subject_code' from the 'Subjects' table. -
FROM Subjects: This line is specifying the 'Subjects' table as the source of the data. -
INNER JOIN Staff ON Subjects.staff_name = Staff.staff_name: This line is joining the 'Subjects' table with the 'Staff' table where the 'staff_name' in both tables match. -
WHERE Staff.staff_name = 'Lakshmi': This line is filtering the results to only include records where the 'staff_name' is 'Lakshmi'. -
ORDER BY Subjects.subject_name ASC: This line is ordering the results in ascending order based on the 'subject_name'.
Similar Questions
Write a query to display the staff_name, subject_name and subject_code details from staff and subject table. Display all the staff_name even if they have not handling any subjects. Display the records sorted in ascending order based on staff_name.Note:1. Display only the staff_name, subject_name and subject_code details from staff and subject table.2. Display all the staff_name even if they have not handling any subjects.3. Use joins. Tables involved are subject and staff4. Order by is mandatory.
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.
Write a query to display all student details whose sname starts with ‘s’(case sensitive) and is of length between 5 and 20 and squal as ‘undergraduate’(case sensitive). Display the records sorted in ascending order based on sid.
Write a MySQL statement to sort the students in descending order of the last name
Write a query to display the person_name and contact_number from the 'travel_card'.Display the records in ascending order based on the person_name.Note:1. Display only the column named person_name and contact_number present in the travel_card table.2. Order by is mandatory
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.