46. Actors and customers whose last name starts with 'A'


  • Write a query to return unique names (first_name, last_name) of our customers and actors whose last name starts with letter 'A'.

Table 1: actor

  col_name   | col_type
 actor_id    | integer
 first_name  | text
 last_name   | text

Table 2: customer

  col_name   | col_type
 customer_id | integer
 store_id    | smallint
 first_name  | text
 last_name   | text
 email       | text
 address_id  | smallint
 activebool  | boolean
 create_date | date
 active      | integer

Sample results

 first_name | last_name
 JOSE       | ANDREW

Solution postgres

SELECT first_name, last_name
FROM customer
WHERE last_name LIKE 'A%'
SELECT first_name, last_name
FROM actor
WHERE last_name LIKE 'A%';


This query is selecting the first name and last name columns from two different tables, "customer" and "actor". It uses the "WHERE" clause to filter the results and only show rows where the last name starts with the letter "A".

The "UNION" operator is used to combine the results of both selects into a single result set, eliminating any duplicates in the process.

Overall, this query is retrieving the first and last names of all customers and actors whose last name starts with the letter "A".

Last Submission postgres

Expected results

More UNION, UNION ALL questions

ID Title Level FTPR
129 Top 3 and bottom 3 courier uber medium
104 MAU: Monthly active users google easy
94 Top 3 products vs. bottom 3 products amazon medium
87 Top song in the US and UK spotify medium
57 Total number of actors (with UNION) easy
47 Actors and customers whose first names end in 'D'. easy