1

I don't really know how to search for this, probably it's quite easy to do it, but I don't know how to do this. I have a SQL table:

| c1 | c2 | c3 | c4 | c5 |
 data data data data data

So I've 5 columns, and now I want to select the rows with only the following (c1, c2, c3) where that row appears more than 5 times in the table Something like this:

  Select c1, c2, c3 
  From table
  having count(*) > 5 and (all in that count, all rows must have the same values on c1, c2, c3)

Can only do this with basical sql queries. Functions, declarations and etc are not allowed. Don't really know if i'm explaining myself well.

1
  • you should write up an example of your dataset and your expected result, that would help a bunch. Commented Jul 28, 2016 at 8:48

3 Answers 3

2

Not absolutely sure I understand, but my guess would be

select c1, c2, c3
from <yourtable>
group by c1, c2, c3
having count(*) > 5
Sign up to request clarification or add additional context in comments.

2 Comments

No, I don't want the row where all value area equal. I want the distinct count of rows, where the row 1 is equal to row 2.
@Elsendion or just remove the where clause
0

This query will return all records from your original table whose c1, c2, and c3 combined values appear in duplicate more than 5 times. I also included the actual count in the result set.

SELECT t1.c1, t1.c2, t1.c3, t1.c4, t1.c5, t2.cardinality
FROM yourTable t1
INNER JOIN
(
    SELECT c1, c2, c3, COUNT(*) AS cardinality
    FROM yourTable
    GROUP BY c1, c2, c3
    HAVING COUNT(*) > 5
) t2
    ON t1.c1 = t2.c1 AND
       t1.c2 = t2.c2 AND
       t1.c3 = t2.c3

Comments

0

Just treat c1,c2,c3 as a single string c1+c2+c3:

SELECT c1, c2, c3 FROM table WHERE
c1 || c2 || c3 IN (
  SELECT c1 || c2 || c3 FROM table
  GROUP BY c1 || c2 || c3
  HAVING COUNT(*) > 5);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.