Home > Software design >  just show not repeated value
just show not repeated value

Time:01-10

This is my table

id c_id number
3444 34 3377752
3446 35 3473747
3447 35 3532061
3454 37 3379243
3455 38 3464467
3456 38 3377493

I want to create a table which is show me not repeated value in a c_id column (repeat just 1 time). the result should be:

id c_id number
3444 34 3377752
3454 37 3379243
GROUP BY  c_id, number
HAVING COUNT(cart_id) = 1

i tried this but it shows me repeated value again

CodePudding user response:

SELECT ANY_VALUE(id) id,
       c_id,
       ANY_VALUE(`number`) `number`
FROM tablename
GROUP BY c_id
HAVING COUNT(*) = 1;

CodePudding user response:

You can do it as follows :

select t.*
from _table t
  inner join (
    select c_id
    from _table
    group by c_id
    having count(1) = 1
) as s on s.c_id = t.c_id;

Check it here : https://dbfiddle.uk/RlxxQ_05

  • Related