Skip to content
RED SAGSkills
easy15 ptsSet Operations

Wishlist Items Also in Cart

A shop tracks saved products in wishlist_items and products currently in the basket in cart_items. The same pair can appear more than once in either table.

Find each distinct (user, product) pair that is both wishlisted and in the cart.

Return columns user_id, product_id. Row order does not matter.

Schema

CREATE TABLE wishlist_items (
  user_id INTEGER NOT NULL,
  product_id INTEGER NOT NULL,
  added_at TEXT NOT NULL
);
CREATE TABLE cart_items (
  user_id INTEGER NOT NULL,
  product_id INTEGER NOT NULL,
  quantity INTEGER NOT NULL
);

Sample data

wishlist_items

user_idproduct_idadded_at
15012026-05-01
15022026-05-02
25012026-05-02
37772026-05-03
26002026-05-04

cart_items

user_idproduct_idquantity
15021
25012
37781
45011
26001
Hint 1

INTERSECT returns the rows that appear in both queries and removes duplicates.

Hint 2

Both columns must match. User 11 with product 6 is not user 6 with product 11.

Good practice for: Data Analyst, Backend Developer, Digital Marketing Specialist, Product Manager

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.