<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/sql-has-rules-you-don-t-notice-until-your-query-is-wrong-ue7ucmkyu" -->

---
title: SQL Has Rules You Don’t Notice Until Your Query Is Wrong
description: A comprehensive guide to SQL behaviors that silently produce wrong results. Covers 20 common pitfalls including NULL three-valued logic, COUNT(*) vs...
canonical: https://daily.dev/posts/sql-has-rules-you-don-t-notice-until-your-query-is-wrong-ue7ucmkyu
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: SQL Has Rules You Don’t Notice Until Your Query Is Wrong | daily.dev
og:description: A comprehensive guide to SQL behaviors that silently produce wrong results. Covers 20 common pitfalls including NULL three-valued logic, COUNT(*) vs...
og:url: https://daily.dev/posts/sql-has-rules-you-don-t-notice-until-your-query-is-wrong-ue7ucmkyu
og:image: https://api.daily.dev/og/posts/Ue7UcMKYu.png
og:image:alt: SQL Has Rules You Don’t Notice Until Your Query Is Wrong
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL Has Rules You Don’t Notice Until Your Query Is Wrong

**[Medium](https://daily.dev/sources/medium_js)** · 12 min read · 0 upvotes · 0 comments

## Summary

A comprehensive guide to SQL behaviors that silently produce wrong results. Covers 20 common pitfalls including NULL three-valued logic, COUNT(*) vs COUNT(column) differences, how LEFT JOINs accidentally become INNER JOINs when WHERE filters NULL rows, JOIN row multiplication and data grain, NOT IN with NULLs, WHERE vs HAVING, GROUP BY vs window functions, ROW_NUMBER/RANK/DENSE_RANK differences, date/timestamp filtering, COALESCE and NULLIF usage, SQL execution order, and a 15-point mental checklist for validating queries before trusting results.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://cgorale111.medium.com/sql-has-rules-you-dont-notice-until-your-query-is-wrong-ebeed875b585>

## Similar posts on daily.dev

- [10 Rare SQL Features Every Developer Should Know](https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx) · Medium · 0 upvotes · 0 comments

---

Tags: [#sql](https://daily.dev/tags/sql)

[View this post on daily.dev](https://daily.dev/posts/sql-has-rules-you-don-t-notice-until-your-query-is-wrong-ue7ucmkyu)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"SQL Has Rules You Don’t Notice Until Your Query Is Wrong","url":"https://daily.dev/posts/sql-has-rules-you-don-t-notice-until-your-query-is-wrong-ue7ucmkyu","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/sql-has-rules-you-don-t-notice-until-your-query-is-wrong-ue7ucmkyu"},"datePublished":"2026-07-23T05:35:45.096Z","dateModified":"2026-07-23T05:36:10.601Z","description":"A comprehensive guide to SQL behaviors that silently produce wrong results. Covers 20 common pitfalls including NULL three-valued logic, COUNT(*) vs...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c121e12353928e06dcf339b60fa49370?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c121e12353928e06dcf339b60fa49370?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/sql-has-rules-you-don-t-notice-until-your-query-is-wrong-ue7ucmkyu","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"sql","timeRequired":"PT12M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"SQL Has Rules You Don’t Notice Until Your Query Is Wrong"}]}
```

