Lookups

Pick a name. Store the key.

Most columns people edit hold a key into another table. A lookup lets them choose by the name they recognise, while the table receives exactly the value it expects.

A lookup cell open in the Data Editor grid, offering product categories by name.
Why it matters

Nobody should have to remember that Finland is region 1

Keys keep a database consistent, and they are the first thing people get wrong.

A lookup column names a lookup table, the column holding the stored value and the column holding the name to show. It can also name a third column with a business code, because the stored value is often a surrogate key nobody recognises.

In the grid, the lookup shows the name, and editing it opens a searchable list. Export writes the code or the name, import matches them back, and the column filter offers the same names. The table only ever receives the key.

Walkthrough

Lookups, step by step

Screens from the product.

Step 1

Choose from names

Editing a lookup cell opens a searchable list of the lookup's names, with NULL always on offer for an empty value and a button to clear the choice.

  • Type to narrow a long list
  • The first 200 matches drawn, for speed on large tables
  • The stored key never has to be typed
A lookup cell being edited, with a searchable list of product categories.
Step 2

Define the lookup once

The dataset owner picks the lookup table, its value column, its display column and an optional code column, then how the cell should read: the name, the value, the code, or one of them with another in braces.

  • display, value, code, or combinations such as display {code}
  • Its own Filter SQL and Order By SQL
  • Any table or view the connection can read
The Lookup for Category dialog: the lookup table, value, display and code columns and the display format.
Step 3

Offer only the values in use

The filter wizard writes the lookup's Filter SQL for you so that it offers only the values the dataset's rows actually use, optionally also applying the dataset's own filter.

  • Generated as an IN (SELECT DISTINCT …) query
  • Shorter lists on large code tables
  • Readable SQL you can still edit by hand
The filter wizard generating a lookup filter that offers only the values used in the dataset.
Step 4

Filter the dataset by its lookups

The dataset's own Filter SQL and Order By SQL can refer to any lookup's table as lookup_<column>, for example to load only the rows of active product categories or to sort by a category's name. The join is added only when the SQL refers to it.

  • One name per lookup column, so two lookups on one table stay separate
  • Wizards to build the condition or the ordering
  • No join at all for datasets that do not use it
Highlights

Lookups everywhere a key appears

The same names in every place a person meets the column.

In the filters

A lookup column's filter is a checklist of names, searchable without regard to case or accents.

In Excel

Export writes the code if the lookup has one, otherwise the name, and import matches either back to the key.

In groups

When a lookup column is the group column, each group row shows the name, not the key.

Related

Keep exploring

Where lookups meet the rest of the product.

Use a lookup in the playground

One of the playground's missions is to give a row its region from a lookup. It takes ten seconds.