COMPANY Database
----------------

Query 0: Retrieve the birthdate and address of the employees whose name is "John B. Smith".

{ u,v | (exists t,w,x,y,z)(
            employee('John','B','Smith',t,u,v,w,x,y,z) ) }

Query 1: Retrieve the name and address of all employees who work for the "Research"
department.

{ q,s,v | (exists r,t,u,w,x,y,z,n,o)(
            employee(q,r,s,t,u,v,w,x,y,z) and 
            department('Research',z,n,o) ) }

Query 2: For every project located in "Stafford", list the project number, the 
controlling department number, and the department manager's last name, 
birth date, and address.

{ i,k,s,u,v | (exists h,q,r,t,w,x,y,z,l,o)(
                projects(h,i,'Stafford',k) and 
                employee(q,r,s,t,u,v,w,x,y,z) and 
                department(l,k,t,o) ) }

Query 6: List the names of employees who have no dependents.

{ q,s | (exists r,t,u,v,w,x,y,z)(
          employee(q,r,s,t,u,v,w,x,y,z) and 
          not ((exists m,n,o,p)(dependent(t,m,n,o,p))) ) }

The following is not SAFE and would not work

{ q,s | (exists r,t,u,v,w,x,y,z)(
          employee(q,r,s,t,u,v,w,x,y,z) and 
         (forall l,m,n,o,p)(not (dependent(l,m,n,o,p)) or t<>l) )}

Query 7: List the names of managers who have at least one dependent.

{ s,q | (exists r,t,u,v,w,x,y,z,h,i,k,m,n,o,p)(
           employee(q,r,s,t,u,v,w,x,y,z) and 
           department(h,i,t,k) and
           dependent(t,m,n,o,p) ) }

MOVIE Database
--------------

(1) Find the directors who have acted in a movie they directed.

{ D | (exists T)(movies(T,D) and actors(T,D)) }

(2) Find the movies that are directed by Kurosawa or are being 
   played in theater Odeon.

{ T | movies(T,'Kurosawa') or (exists S)(plays('Odeon',T,S)) }

(3) Find the directors such that EVERY actor has acted in at 
    least one of his or her movies.

{ D | (exists Z)(movies(Z,D) and 
         not((exists A,X,Y)(movies(X,D) and actors(Y,A) and 
                            not((exists T)(actors(T,A) and movies(T,D))))))}
(4) Find actors who act ONLY for director Kurosawa.

{ A | (exists X)(actors(X,A) and 
          not((exists T)(actors(T,A) and not(movies(T,'Kurosawa')))))}

(5) Find all pairs of actors who act in EXACTLY the same movies. 

{ X,Y | (exists T1,T2)(actors(T1,X) and actors(T2,Y) and X<Y and
   not ((exists U,S)(actors(U,Y) and actors(S,X) and not (actors(S,Y)))) and
   not ((exists V,T)(actors(V,X) and actors(T,Y) and not (actors(T,X)))) 
 )}


MODB Database
-------------

(2a) Retrieve the names of parts that cost less than $20.00.

{name | (exists p,q,r,o)(parts(p,name,q,r,o) and r < 20.00) }

(2b) Retrieve the names and cities of employees who have taken 
     orders for parts costing more than $20.00 

{name,city | (exists e,z,h,o,c,r1,s,p,q,n,a,r2,l) (
                 employees(e,name,z,h) and 
                 zipcodes(z,city) and
                 orders(o,c,e,r1,s) and 
                 odetails(o,p,q) and 
                 parts(p,n,a,r2,l) and r2 > 20.00 ) }

(2c) Retrieve the pairs of customer number values of customers 
     who live in the same zip code.

{n1,n2 | (exists m1,s1,m2,s2,z,p1,p2)(customers(n1,m1,s1,z,p1) and
                   customers(n2,m2,s2,z,p2) and 
                   n1 < n2  ) }

(2d) Retrieve the names of customers who have ordered parts ONLY
     from employees living in the city of Wichita.

{name | (exists cno,a,b,c)(
           customers(cno,name,a,b,c) and
           not ((exists d,e,f,g,h,i,j,city)(
                  orders(d,cno,e,f,g) and employees(e,h,i,j) and
                  zipcodes(i,city) and city <> 'Wichita'
               ))
        )
}

(2e) Retrieve the names of customers who have ordered ALL parts 
     costing less than $20.00.

{name | (exists cno,a,b,c)(
           customers(cno,name,a,b,c) and
           not ((exists pno,price,d,e,g,u,v,w,x)(
                  parts(pno,d,e,price,g) and
                  price < 20 and
                  customers(cno,u,v,w,x) and
                  not ((exists ono,h,i,j,k)(
                         odetails(ono,pno,h) and
                         orders(ono,cno,i,j,k)
                       ))
               ))
        )
}

(2f) Retrieve the names of customers who have NOT placed any
     order.

{name | (exists cno,a,b,c)(
           customers(cno,name,a,b,c) and
           not ((exists d,e,f,g)(orders(d,cno,e,f,g)))
        )
}

(2g) Retrieve the names of customers who have placed EXACTLY two 
     orders.

{name | (exists cno,a,b,c)(
           customers(cno,name,a,b,c) and
           (exists d,e,f,g,h,i,j,k)(
             orders(d,cno,e,f,g) and
             orders(h,cno,i,j,k) and d<>h) and
           not ((exists d1,e1,f1,g1,d2,e2,f2,g2,d3,e3,f3,g3)(
                  orders(d1,cno,e1,f1,g1) and
                  orders(d2,cno,e2,f2,g2) and
                  orders(d3,cno,e3,f3,g3) and
                  d1<>d2 and d2<>d3 and d1<>d3
               ))
        ) 
} 

(3) A few additional ones on table "numbers"

{x | numbers(x,x,x,x,x)}

{x,y | numbers(x,y,x,y,x) }

{x,y,z | numbers(x,y,z,y,x) }

{x,y | numbers(x,y,3,y,x) }