user5653890
user5653890

Reputation: 15

How to formulate "at most" in domain relational calculus

How do I formulate "at most" in domain relational calculus?

Example queries:

Dish: dish_id, name
Have: dish_id, ing_id
Ingredient: ing_id, name

Upvotes: 0

Views: 113

Answers (1)

philipxy
philipxy

Reputation: 15118

There exist at least N ids when/iff there exist N ids.

-- there exists (at least) 1 id where p
exists x | p

-- there exist (at least) 2 ids where p
exists x,y | x<>y AND p

-- there exist (at least) 3 ids where p
exists x,y,z | x<>y AND x<>z AND y<>z AND p

There exist at most N ids when/iff NOT there exist N+1 ids.

-- there exist at most 2 things where p
-- NOT there exist (at least) 3 ids where p
NOT (exists x,y,z | x<>y AND x<>z AND y<>z AND p)

There exist exactly N ids when/iff there exist (at least) N ids and there exist at most N ids. Which is when/iff there exist (at least) N ids and NOT there exists one more id.

PS Be sure to know whether you want at least 1.

PS Difference between Relational Algebra and Relational Calculus

Upvotes: -1

Related Questions