Use a UNION to create a list of all the employee's and customer's first names and last names ordered by the last name in descending order.
Question
Use a UNION to create a list of all the employee's and customer's first names and last names ordered by the last name in descending order.
Solution
Sure, I can help with that. However, I need to know the structure of your tables to provide an accurate SQL query. Assuming you have two tables, employees
and customers
, and both of them have first_name
and last_name
columns, the SQL query would look like this:
SELECT first_name, last_name
FROM employees
UNION
SELECT first_name, last_name
FROM customers
ORDER BY last_name DESC;
Here's a step-by-step breakdown of the query:
-
SELECT first_name, last_name FROM employees
: This part of the query selects the first and last names of all employees. -
UNION
: This keyword combines the results of two or more SELECT statements without returning any duplicate rows. -
SELECT first_name, last_name FROM customers
: This part of the query selects the first and last names of all customers. -
ORDER BY last_name DESC;
: This part of the query sorts the combined list of employees and customers by last name in descending order.
Please replace employees
and customers
with your actual table names, and first_name
and last_name
with your actual column names if they are different.
Similar Questions
Show unique first names from the patients table which only occurs once in the list.
Select all records from the Customers table, sort the result reversed alphabetically by the column City.
Write a program that would print the information (name, year of joining, salary, address) of threeemployees by creating a class named 'Employee
Create and print a linked list with four (4) elements. The first letter of your last name will be the basis of the required values for your linked list.
Write a MySQL statement to sort the students in descending order of the last name
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.