Well I tried it like this and it just pasted all original 13925 records into a new table. I tried using the primary key as my join. Then the second code I am trying by taking toprank and = to toprank and that is still running.
Code:
SELECT IP.cm_id, IP.ipop, IP.legacy, IP.toprank, IP.topdx1, IP.topdx1desc, IP.dx2, IP.dx2desc, IP.membercount, IP.admitqty, IP.state, IP.product INTO a
FROM IP
WHERE (((IP.[toprank]) In (SELECT TOP 5 tr.toprank
FROM ip as tr
where tr.cm_id = ip.cm_id
ORDER BY tr.membercount DESC)))
GROUP BY IP.cm_id, IP.ipop, IP.legacy, IP.toprank, IP.topdx1, IP.topdx1desc, IP.dx2, IP.dx2desc, IP.membercount, IP.admitqty, IP.state, IP.product
ORDER BY IP.membercount DESC;
Code:
SELECT IP.cm_id, IP.ipop, IP.legacy, IP.toprank, IP.topdx1, IP.topdx1desc, IP.dx2, IP.dx2desc, IP.membercount, IP.admitqty, IP.state, IP.product INTO a
FROM IP
WHERE (((IP.[toprank]) In (SELECT TOP 5 tr.toprank
FROM ip as tr
where tr.toprank = ip.toprank
ORDER BY tr.membercount DESC)))
GROUP BY IP.cm_id, IP.ipop, IP.legacy, IP.toprank, IP.topdx1, IP.topdx1desc, IP.dx2, IP.dx2desc, IP.membercount, IP.admitqty, IP.state, IP.product
ORDER BY IP.membercount DESC;