Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query to select from same column but multiple values

Tags:

sql

mysql

This is my table.

id  customer        product 
1   Tizag           Pen 
4   Gerald Garner   19" LCD Screen  
5   Tizag           19" LCD Screen  

I want to select the customer who has both "Pen" and '19" LCD Screen'. So, the result with be customer 'Tizag'.

How can I do this.

Thanks And Regards, Rupak Banerjee.

like image 864
Rupak Banerjee Avatar asked Dec 13 '25 01:12

Rupak Banerjee


1 Answers

Try this:

SELECT customer FROM table t1
JOIN table t2 USING( customer )
WHERE t1.product = 'Pen'
AND t2.product = '19" LCD Screen'

However, the query needs to change if you change the number of products. There might be a better way to do this, but I think this will work.

like image 120
kitti Avatar answered Dec 14 '25 17:12

kitti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!