What is easier to read in EXISTS subqueries? [closed] What is easier to read in EXISTS subqueries? [closed] sql sql

What is easier to read in EXISTS subqueries? [closed]


Intuitive is ...EXISTS (SELECT * .. because you really don't care

  • The only keyword of importance is EXISTS
  • The choice of ...EXISTS (SELECT 1 .. perpetuates the general myths and superstitions around EXISTS (eg comments on the MySQL docs).
  • ANSI standard says "doesn't matter"
  • It's more interesting to understand that EXISTS is a semi-join.


I still use EXISTS (SELECT * ...), for historical (gbn: should that be hysterical?) reasons. Technically, there is no difference, of course; the optimiser / planner will throw it away and reduce it to one bit of information. For the human reader the * looks more special, it will stand out as a special symbol, and not as a value or constant. Also, I tend to reduce the amount of literals and magic constants in my programs (eventually, only 0 and 1 should remain).


In the context of EXISTS the SQL optimizer knows that it doesn't matter what it returns as long as it returns something. So to you it doesn't matter.

For the intuitive part: I don't think * will be right.

It's better to ask in words: "check whether even the slightest part exists" - meaning 1 (or something else).