sql - Specifying "AND" Condition with more than 1 time for same column in MYSQL -


i have table like:

product_id | attribute_id | text -------------------------------- 52         | 16           | 1.0 inch - 2.9 inches 52         | 15           | radio 52         | 14           | simple phones 134        | 16           | 1.0 inch - 2.9 inches 134        | 15           | wifi 134        | 14           | dual sim phones 

i writing query getting products simple phones 1.0 inch - 2.9 inches screen.

i want place 2 conditions 1 column.

when writing query:

select       *        product_attribute         (text = '1.0 inch - 2.9 inches')        ,        (text = 'simple phones') 

so getting "0 results". while running following query:

select       *        product_attribute         text in('1.0 inch - 2.9 inches','simple phones') 

then getting following result:

product_id | attribute_id | text -------------------------------- 52         | 16           | 1.0 inch - 2.9 inches 52         | 14           | simple phones 134        | 16           | 1.0 inch - 2.9 inches 

but need product_id = 52 because product has both filters either 1.0 inch - 2.9 inches , simple phones while product_id = 134 has 1.0 inch - 2.9 inches

please me out sort out problem.

** sorry english :)

use having clause:

select * product_attribute  text in('1.0 inch - 2.9 inches','simple phones') group product_id having count(product_id)=2 

see example in sql fiddle.

edit:

for getting records:

select * product_attribute t1 left join   (select product_id    product_attribute     text in('1.0 inch - 2.9 inches','simple phones')    group product_id    having count(product_id)=2) t2 on t1.product_id=t2.product_id t2.product_id not null , t1.text in('1.0 inch - 2.9 inches','simple phones') 

result:

product_id    attribute_id  text 52            16            1.0 inch - 2.9 inches 52            14            simple phones 

see result in sql fiddle.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -