Skip to content
Advertisement

select columns’ values based on another two values from another column

I have this data set and I need to extract multiple columns values based on on column value.

To elaborate on it, I have a rental table, inventory table, customer table, and I want to relate customer table to rental table by customer_id and relate rental table to inventory table by inventory_id, the final purpose is to generate first_name and last_name of customers of specified customer_id.

by

I have achieved the result of

However I want to take a step further to obtain the following table

Which is to obtain column values customer_id,first_name and last_name by checking the occurrence of customer_id for both store_id='1' and store_id='2'. I know that I need to do COUNT (DISTINCT customer_id) but I cannot figure out how to apply to achieve it. Any help will be very much appreciated!

Advertisement

Answer

Are you looking for customers of both stores? One method uses exists:

However, if you just want the customers who have purchased in both stores, you can use the simpler query:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement