A challenge by Decision Management Community.

A zoo has four monkeys, during the monkey lunchtime each one ate a different fruit in their favourite resting place. Sam, who doesn’t like bananas, likes sitting on the grass. The monkey who sat on the rock ate the apple. The monkey who ate the pear didn’t sit on the tree branch. Anna sat by the stream but she didn’t eat the pear. Harriet didn’t sit on the tree branch. Mike doesn’t like oranges.

1. What kind of fruit each monkey ate?
2. Where their favourite resting place was?

So, how to solve this in SQL? It is easy to identify domains, predicates and rules; after that it is straightforward.

### Domains

```Monkey {Sam, Anna, Harriet}
Fruit  {banana, pear, apple, orange}
Place  {grass, rock, tree, stream}
```

### Rules

1. Sam does not like bananas.
2. Mike does not like oranges.
3. Anna didn’t eat the pear.
4. Harriet didn’t sit on the tree branch.
5. Anna sat by the stream.
6. Sam likes sitting on the grass.
7. The monkey who sat on the rock ate the apple.
8. The monkey who ate the pear didn’t sit on the tree branch.

### Solution

The SQL code is easy to follow, it has been tested on PostgreSQL and MS SQL Server.

```sol_no  monkey  place   fruit
-------------------------------
1       Anna    stream  orange
1       Harriet rock    apple
1       Mike    tree    banana
1       Sam     grass   pear
```