Show first and last name, allergies from patients which have allergies to either 'Penicillin' or 'Morphine'. Show results ordered ascending by allergies then by first_name then by last_name.
Question
Show first and last name, allergies from patients which have allergies to either 'Penicillin' or 'Morphine'. Show results ordered ascending by allergies then by first_name then by last_name.
Solution
This question seems to be asking for a SQL query. Here's how you can do it:
SELECT first_name, last_name, allergies
FROM patients
WHERE allergies IN ('Penicillin', 'Morphine')
ORDER BY allergies ASC, first_name ASC, last_name ASC;
Here's a step-by-step breakdown of the query:
-
SELECT first_name, last_name, allergies: This part of the query specifies the columns that you want to display in your result, which are first_name, last_name, and allergies. -
FROM patients: This part of the query specifies the table from which to retrieve the data, which is the patients table. -
WHERE allergies IN ('Penicillin', 'Morphine'): This is the condition for the query. It will only select the rows where the allergies column contains either 'Penicillin' or 'Morphine'. -
ORDER BY allergies ASC, first_name ASC, last_name ASC;: This part of the query specifies the order in which to display the results. It will first order the results by allergies in ascending order. If there are multiple rows with the same allergy, it will then order those rows by first_name in ascending order. If there are still multiple rows with the same first_name, it will finally order those rows by last_name in ascending order.
Similar Questions
Show unique first names from the patients table which only occurs once in the list.
Find out the names of any five common antibiotics
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.
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.
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.Sample Output:
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.