n00b0101
asked on
mssql - group by & order by?
I keep getting this error:
Incorrect syntax near the keyword 'ORDER'.
Basically, I'm trying to find all the rows grouped by email that have a count = 4. I want those 4 to be ordered by the time field so that I can pull the entries in chronological order.
Incorrect syntax near the keyword 'ORDER'.
Basically, I'm trying to find all the rows grouped by email that have a count = 4. I want those 4 to be ordered by the time field so that I can pull the entries in chronological order.
insert into TableB
( qid, rep, time, email, idmarker )
(
select TOP 2 qid, rep, time, email, idmarker
FROM TableA
WHERE email IN
(
select email FROM
tableA
group by email
having COUNT(*) = 4
)
ORDER BY time
)
GO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
insert into TableB
( qid, rep, time, email, idmarker )
(
select TOP 2 qid, rep, time, email, idmarker FROM TableA
WHERE email IN
(select email FROM tableA group by email having COUNT(*) = 4)
)
ORDER BY time
)
GO