0%

Ask Precise Questions · practice

Name Result Columns with AS

The shortlist values are useful, but its headings still speak in stored column names such as asset_tag and loan_days. A compact report can call those same result columns tag, item, and days without changing the catalog underneath.

Replace the SELECT line in search.sql with this multi-line projection:

SELECT
    asset_tag AS tag,
    name AS item,
    loan_days AS days

Keep the existing FROM, filter, complete order, and limit. Press Run and inspect the headings:

Columns: tag | item | days
TL-100 | Cordless drill | 7
EV-101 | Folding table | 7

AS gives a result column an alias, which is another name used for this answer. asset_tag AS tag still reads values from the stored asset_tag column. It only asks SQLite to label that result position tag.

The stored table has not been renamed. Another query can still ask for asset_tag, name, and loan_days, and later clauses in this query still refer to the underlying item data. You are shaping the answer for its reader rather than redesigning the database.

Think of the projection as a small handoff. SQLite reads asset_tag from each chosen row, then hands that to the result under the heading tag. The stored value is unchanged, and the same row still carries its original name and loan_days values.

You also removed category from the result. The WHERE clause may use a column without displaying it, just as the order may use id without displaying it. Filtering, ordering, and choosing result columns are related parts of one query, but each has its own job.

SQLite also accepts an alias without the optional word AS, such as asset_tag tag. The version shown here is worth reading first because AS makes the rename visible. Submit accepts either spelling when the headings and values are right.

Do not write 'tag', 'item', and 'days' as quoted result values. That would repeat those words in the rows instead of labeling columns containing catalog data. Check the Columns: line after Run to see the distinction.

Your two-row shortlist now presents exactly three useful fields under reader-friendly names while the original table design stays untouched.

Task

Change the result in search.sql to three columns headed tag, item, and days, using asset_tag, name, and loan_days in that order.

Keep the existing filter, sort, and LIMIT 2, then run and submit the query.