Back to Delete

qSQL · Delete · Practice Question

Delete a Column from a Table

Sign in to track your progress

Remove a Column from a Table

Question

Given the following table:

t:([] sym:`AAPL`MSFT`GOOG`TSLA`NVDA;
      qty:100 200 150 75 300;
      price:185.25 410.10 142.80 238.50 875.20)

Return the table without the price column.

Solution

Method 1

delete price from t

Method 2

(enlist `price) _ t

Result:

sym  qty
--------
AAPL 100
MSFT 200
GOOG 150
TSLA 75
NVDA 300

Explanation

The qSQL delete statement can be used to remove a column from a table:

delete price from t

This returns a new table without the price column.

The same result can be achieved using the Drop operator _:

(enlist `price) _ t

Here:

enlist `price

creates a one-item symbol list containing the column name to remove.

The _ operator removes that column from the table.

Both methods return the table with only the remaining columns:

sym  qty
--------
AAPL 100
MSFT 200
GOOG 150
TSLA 75
NVDA 300

The qSQL version is usually clearer, while the _ version is useful when the columns to remove are stored in a variable.