Back to Selecting Data

In Memory Tables · Selecting Data · Practice Question

Delete a Row by Index

Sign in to track your progress

Question

Given a table t, delete the second row (index 1) from the table.

For example:

t:([] sym:`AAPL`MSFT`GOOG; price:185.25 410.1 142.8)

Solution

delete from t where i = 1

Alternative Solution

t _ 1

Explanation

Inside a qSQL query, i refers to each row's position in the table — so delete from t where i = 1 deletes whichever row currently sits at index 1, regardless of its column values.

_ (drop) is the list-level equivalent: t _ 1 drops the item at index 1 from the table, the same way l _ 1 would drop the item at index 1 from a plain list. Since a table is just a list of rows under the hood, both approaches remove the same row.