skip to Main Content

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

2

Answers


  1. SELECT ANY_VALUE(id) id,
           c_id,
           ANY_VALUE(`number`) `number`
    FROM tablename
    GROUP BY c_id
    HAVING COUNT(*) = 1;
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search