SQL query for customer who checked out one item before checking out another

say I have a table like this: Rental_list

Customer Product Date
James basketball 01-05-2020
Sam baseball 02-15-2020
Sam soccer ball 02-20-2020
Jen Basketball 03-15-2020
Jen baseball 03-29-2020
James soccer ball 04-19-2020

I want a result to show me people who rented a baseball before renting a soccer ball. The result should be Sam, who rented a baseball on 2-15 and a soccerball on 2-20

I know if i was simply looking for the customers first purchase i could use something like select name, min(date) from rental_list group by name

and i know the below would just provide the names of the two people who rented baseballs.

select name, min(date) from rental_list where product = 'baseball' group by name

so how can i make it so it pulls only sam, who rented a baseball then a soccerball?

Read more here: https://stackoverflow.com/questions/68459259/sql-query-for-customer-who-checked-out-one-item-before-checking-out-another

Content Attribution

This content was originally published by sqlnoob at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: