0

I would like to write a query to pick out rows with the same cottageid, from, and to values, so in this case it would pick out the rows with the id 991, and 992. The table name is datesBooked.

enter image description here

1
  • Oh i forgot to add, i have over a thousand entries in this table and more than just two for cottageid 6, cottageid6 is also not the only one with multiple entries. Commented May 14, 2013 at 10:41

2 Answers 2

2

You can join the table with itself:

select d1.id,d2.id from datesBooked d1
   inner join datesBooked d2 on 
      d1.cottageid=d2.cottageid
      and d1.from = d2.from
      and d1.to = d2.to
      and d1.id<d2.id

That would give you the duplicates. I am only getting the ones that have lesser id than the following one (that way you will get the duplicates in the right column, and the originals in the first one)

Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

SELECT * FROM datesBooked
GROUP BY cottageid, from, to
HAVING COUNT(cottageid) > 1

1 Comment

Sorry but this just gives me 22k results. Thanks for trying though. :)

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.