Database Queries

Once we’ve created our database, we can start playing with it. We’ll start by looking at Mnesia queries. As you look through this, you might be surprised to see that Mnesia queries look a lot like both SQL and list comprehensions, so there’s actually very little you need to learn to get started. In fact, it really isn’t that surprising that list comprehensions and SQL look a lot alike. Both are based on mathematical set theory.

In all our examples, I’ll assume that you have created a database with two tables called shop and cost. These tables contain the data shown in Table 8, The shop Table and Table 9, The cost Table.

Table 8. The shop Table

Item

Quantity

Cost

apple

20

2.3

orange

100

3.8

pear

200

3.6

banana

420

4.5

potato

2456

1.2

Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.