Menu
CoddyTech

Choose Your Columns

Part of the First Queries section of Coddy's PostgreSQL journey. Lesson 2 of 20.

A product row has several attributes. Selecting only the columns needed for a question makes the result easier to read. Put their names after SELECT, separated by commas.

Input table products:

idnamecategorypricestockactivenote
1Maptravel125TrueNULL
2Notebookbooks80TrueRecycled
3Atlasbooks243FalseNULL
4Mughome128TrueBlue
5lamphome302FalseClearance
6Mini maptravel610TrueNULL
SELECT name, stock FROM products;

The result has two columns: name followed by stock. For the Map row these are Map and 5. Listing columns chooses their output order; it does not rearrange the stored table.

List output columns after SELECT and the source table after FROM. SELECT * reads all columns.

challenge icon

Challenge

Easy

The stock team needs product identifiers and quantities. Return id and stock, in that column order, for every product. Row order does not matter yet.

The input tables are shown in the test panel. Each run starts from fresh data. Return the named columns in the stated order; do not hard-code the displayed rows.

Try it yourself

-- Write your SQL here.
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in First Queries

Practice on your own: PostgreSQL playground