What do I have to SELECT
in sub query of a WHERE EXIST
clause?
Here is a random query with a WHERE EXIST
clause:
SELECT a.*
FROM a
WHERE EXISTS
(SELECT *
FROM b
WHERE b.a_id = a.id)
So, *
is selected in b
. But it makes no sense to me because I don't want to select anything (unless I misunderstood the behavior of WHERE EXIST
). I could have selected 1
but that seems weird too.
I think it does not really matter in term of execution speed and anything could have worked, but it could matter in terms of readability and "semantics". (I'm not sure about the words I use!). Is there any best practice for this? If so, why one way is chosen over another?