I was recently asked the following question during an interview:
Return all duplicate rows in a table that are between two different
dates / times.
My best guess is:
SELECT *,
COUNT(LogDate) AS NumOccurrences
FROM LogTable
WHERE LogDate > "SomeDate"
AND LogDate < "SomeDate"
GROUP BY LogDate
HAVING ( COUNT(LogDate) > 1 )
Am I in the ballpark? Any thoughts on the right answer?
Thanks.
No need to count(*) in the select (not as your question is formulated at least).
All fields in the select must be in the GROUP BY clause (but you can have more in the GROUP BY than in the SELECT, of course)