Different database queries

21 Views Asked by At

We have the table person (pid,pname) We want to find the names of the persons. What is difference between a and d? I know that d is the correct answer but I don't understand why.

$$a)\, \{\langle X\rangle \mid \forall Y\, (\textrm{person}(Y,X))\}.$$ $$d)\, \{\langle X\rangle\mid \exists Y\, (\textrm{person}(Y,X))\}.$$

original image

2

There are 2 best solutions below

0
On

a) says that for every id $Y$, the name matches $X$, i.e. this set contain $X$ only if all names were equal to $X$.

0
On

a) would give you the list of all pnames (X) that are are associated will all pids (notice the "for all" ($\forall$) quantifier before the Y). Assuming that pids are unique (they usually are keys), this would give you an empty list if you had 2 different persons in the list.

d) gives you the list of all existing pnames (X), because it is only required that at least one pid exists ($\exists$ before the Y) such that (Y,X) is in the database. In your database, each entry must be of the form (pid, pname), so each existing pname must have (at least one) pid that occurs with it, so query d) finds it.