E
E
Ellik2015-11-20 22:31:18
MySQL
Ellik, 2015-11-20 22:31:18

How to select the id of a record from a table where two keys match?

SELECT entity_id FROM products WHERE value_id = '19' and value_id = '12'

There is an entity_id in the products table whose value_id is 19 and 12. How to choose this id?
Or such a request
SELECT entity_id FROM products WHERE value_id = '19' and (value_id = '2' OR value_id = '12')

e3baaa81223a4c9596cdfd1abe1cabf7.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-11-20
@Ellik

SELECT `p1`.`entity_id` 
    FROM `products` AS `p1`
    JOIN `products` AS `p2` USING(`entity_id`)
    WHERE `p1`.`value_id` = '19' 
        AND `p2`.`value_id` = '12'

S
sunrails, 2015-11-20
@sunrails

SELECT entity_id FROM products WHERE value_id IN (19, 12);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question