I need help to get a solution for this condition. I have a table containing records, there is a sku field, in this record I have sku several times. Table structure similar to got rid | identifier | Code | name
rid - auto_increment, where id is varchar, if any sku is available in the table several times, the entry looks like this:
rid id sku name --- -- ------ -------------- 1 3 rs-123 test product 2 3 rs-123 test product 3 4 rs-125 test product 2 4 4 rs-125 test product 2 5 4 rs-125 test product 2 6 6 rs-126 test product 3
I used this sql statement to get records that appear only once
SELECT * FROM test GROUP BY id HAVING ( COUNT(id) = 1 )
This leads to the fact that records are added only once, therefore, according to the above description, only record 6 is the output
I tried changing the above code to this to get the result of entries that are added 2 times
SELECT * FROM test GROUP BY id HAVING ( COUNT(id) = 2 )
The result that I get relates to the record that is added 2 times, but the problem is that only one record appears on the output, for example:
rid id sku name --- -- ------ ------------ 1 3 rs-123 test product
I need to get all rows of records that are added 2 times to the database. Please, help
source share