3

My fields are

ID | Name | StartTime | EndTime | Date | Description

I am looking for a way to select all rows with the same entries in all fields except for the ID.

I am not that familiar with SQL so I tried this approach but there is only one field relevant not (as in my case) five.

My first idea was to try something like:

SELECT *
FROM Table
order by Name, Date, StartTime, EndTime, Description

if I would look through all entries I would at least find the duplicates but that is definitely not the best way to solve the problem.

4 Answers 4

2

This should do what you need:

select Name, Date, StartTime, EndTime, Description
from   table
group by Name, Date, StartTime, EndTime, Description
having count(*) > 1
Sign up to request clarification or add additional context in comments.

Comments

1

This query should work for you:

SELECT ID, Name, StartTime, EndTime, Date, Description
FROM (
    SELECT 
        ROW_NUMBER() OVER (PARTITION BY ID ORDER BY ID, Name, Date, StartTime, EndTime, Description) AS 'IndexNr'
        , ID
        , Name
        , StartTime
        , EndTime
        , Date
        , Description
    FROM Table) AS ResultSet
WHERE ResultSet.IndexNr > 1

Comments

1

Try below query.

SELECT     Name, Date, StartTime, EndTime, Description
FROM    Table
GROUP BY Name, Date, StartTime, EndTime, Description
HAVING      (COUNT(*) > 1)

Comments

-1

You can try this:-

SELECT *
FROM TAB_NAME
HAVING COUNT(CONCAT(Name, StartTime, EndTime, Date, Description)) > 1

This will give you all the rows that are repeated except than the ID.

3 Comments

you can't use "HAVING" without "GROUP BY"
@t-clausen.dk I think the query is executable, you must give it a try first. Having is only used when we have to put a aggregate function in the cond. It has no relation with the group by claue. you must refer some docs for this.
ok, I am refering to some docs now. Look at all the other answers. Also your syntax would be slow if it worked. If you had 2 rows with the values: null, null, null, 'A' and 'A', null, null, null they would be considered identical in this match. You can not use wildchar eather while using a group by. So everything is wrong.

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.