Re: DB gurus: SQL question
Posted: Mon Mar 17, 2008 4:30 pm
My problem is that it won't let me select multiple columns when I use the HAVING clause. This query:
returns this error:
Column 'tbl_PurgeTestData.UID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I have two queries that I believe can give me what I need, I just can't figure out how to make the join work.
This one:
Gives me all the records that are older than 3 days.
And this one:
Gives me all the duplicate ComputerName records. I just can't figure out how to join on those and delete.
Code: Select all
select ComputerName, UID
from tbl_PurgeTestData
group by ComputerName
having count(ComputerName) > 1
Column 'tbl_PurgeTestData.UID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I have two queries that I believe can give me what I need, I just can't figure out how to make the join work.
This one:
Code: Select all
SELECT *
FROM tbl_PurgeTestData
WHERE DATEDIFF(day, LoginTime, GETDATE()) > 3
ORDER BY LoginTime DESC
And this one:
Code: Select all
SELECT ComputerName
FROM tbl_PurgeTestData
GROUP BY ComputerName
HAVING COUNT(ComputerName) > 1
ORDER BY ComputerName