Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    I will clarify that I intended "unique key" with the "key = value" clause but other than that I'm still behind my answer. Commented Sep 26, 2019 at 8:49
  • 1
    OK. With that premise indeed the query would return just one or zero record. BUT: The question does not limit to a unique column. Also: The 2nd query count(1) is equivalent to count(*) from a practical POV. Commented Sep 27, 2019 at 10:54
  • 1
    The question says "what's the proper way to verify the existence of A record". I interpreted that as singular, as in: 1 record. The difference between count(*) and count(1) is already covered by my answer. I prefer count(1) because it does not rely on a specific RDBMS implementation. Commented Sep 27, 2019 at 11:14
  • If unique_key is indexed, is it guaranteed that the statement will run strictly under linear time? Commented Mar 8, 2023 at 4:27
  • 1
    @McSinyx in theory that is correct, although it totally depends on the specific RDBMS implementation that you are running this on. Commented Mar 9, 2023 at 7:19