Hi there
AS always any help gratefully received.
I have a problem filtering records in a query with nested query. As you will see from the SQL below, I want to filter records based on a nested query with a record count < 2.
For some reason I cant work out, the result is ignoring the HAVING COUNT(*) < 2. Can anyone see an obvious problem?
Regards ACO
AS always any help gratefully received.
I have a problem filtering records in a query with nested query. As you will see from the SQL below, I want to filter records based on a nested query with a record count < 2.
For some reason I cant work out, the result is ignoring the HAVING COUNT(*) < 2. Can anyone see an obvious problem?
Regards ACO
Code:
SELECT --COUNT(*)
e.SerialNo, Field1, Field2
FROM ETable e INNER JOIN MTable m ON e.SerialNo = m.SerialNo
WHERE e.Field1 = 2
AND m.Field2 = 1
AND e.SerialNo IN
(
SELECT SerialNo
FROM UTable
WHERE Field1 <> 1
GROUP BY SerialNo HAVING COUNT(*) < 2