I have a SQL query which I only ever want to return 1 row. If there are multiple rows, I want to return null.
I guess I can do it with something like
SELECT whatever FROM MyTable
WHERE something = myQuery
AND ( COUNT(SELECT whatever FROM MyTable
WHERE something = myQuery) = 1)
but that's pretty nasty and I wondered if there as a neater way of doing it.
Cant you do:
SELECT whatever FROM
(
SELECT whatever, COUNT(*) As NumRecords
FROM MyTable
WHERE something = myQuery
GROUP BY whatever
HAVING NumRecords = 1
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With