Back to Selecting Data

In Memory Tables · Selecting Data · Practice Question

Select Rows Where a Column Matches a Pattern

Sign in to track your progress

Question

Given a table t with a symbol column a, select the rows where a takes values beginning with "m" or "n".

For example:

t:([] a:`msft`nflx`aapl`meta`nvda; b:1 2 3 4 5)

Solution

select from t where a like "[mn]*"

Alternative Solution

select from t where any a like/: ("m*";"n*")

Alternative Solution

select from t where (a like "m*") or (a like "n*")

Explanation

like matches a symbol or string against a glob-style pattern. The character class "[mn]*" matches anything starting with m or n, in a single pattern — the cleanest way to express "starts with one of these letters".

The first alternative tests both patterns separately using each-right (/:): for every row's value in a, like/: pairs it against each of "m*" and "n*", producing two boolean columns, which any then collapses row by row into "matched at least one pattern".

The second alternative spells out the same logic with two separate like checks joined by or — functionally identical, just without the iterator.