How to write complex SQL queries with universal quantification

  1. write something that feels correct and pray it works;
  2. translate the query from English to logic then to SQL.
  1. Implication: (p → q) ≡ (¬p ∨ q)
  2. Universal quantification: ∀x f(x) ≡ ¬∃x ¬f(x)
  3. Double negation: ¬¬p ≡ p
  4. De Morgan’s laws: ¬(p ∧ q) ≡ (¬p ∨ ¬q) and ¬(p ∨ q) ≡ (¬p ∧ ¬q)


Image describing the database structure
Structure of the relations
Original query
Simplification of the formula
The query result in set form
Query in SQL

 by the author.




Too lazy to open up a blog

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Run a .NET Core app in a Docker container with SSH access

Switch Statements | C#

From Agile to systems thinking: lessons on company culture

Technology Radar May 2018 review — Part 3



Is C#7 starting to look like a functional language?

It’s about the seeds, not the harvest: some words of advice to fellow learners of code

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Too lazy to open up a blog

More from Medium

SQL Performance Tunning

Temporary Tables in SQL Server and # vs ##

Understanding SQL MERGE Statement for Better Performance.

What I Learned at Work this Week: More Difficult SQL Parsing