O
O
Optimus2017-08-22 11:22:02
MySQL
Optimus, 2017-08-22 11:22:02

How to select an id for which there is only one entry in the table?

Sampling by id=11 produces one row Sampling by id=12 produces three rows of id-shnikov there is a small array, how can I get in the response only those ids for which only one record was found? (i.e. in the example above, the answer should have one line with id=11)
SELECT * FROM `table` WHERE `goods_id`=11
SELECT * FROM `table` WHERE `goods_id`=12

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2017-08-22
Pyan @marrk2

select goods_id from tablename where goods_id in (?) group by goods_id having count(*)=1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question