I have an inherited an incredibly ugly SQL statement
that returns the lowest error state. Of course, there is now a new error check that needs to return, prior to other checks. Rather than renumbering all the codes (shudder), I was thinking - what about using a priority for the error codes, then select...
So - If the interior part of the ugly SQL statement returns something like:
(Key, error code, priority)
What I would want returned as a result would be:
(Lowest code for lowest priority of each key.)
How do I get there?
Thx.
SQL:
INSERT INTO tmptbl (KEY, ERROR)
SELECT KEY, MIN(ERROR) AS ERROR
FROM (<incredibly ugly statement>) AS Q
GROUP BY KEY
So - If the interior part of the ugly SQL statement returns something like:
(Key, error code, priority)
Code:
ABC, 41, 3
ABC, 72, 2
ABC, 99, 2
DEF, 66, 3
What I would want returned as a result would be:
Code:
ABC, 72
DEF, 66
How do I get there?
Thx.