No-account exercise · SELECT

Select the correct columns

Show only the name and price of each product.

Business context

A catalog team prepares an export intended for a comparison page. It needs the business name and price, but not the technical identifiers or category. Explicitly choosing the columns reduces noise and stabilizes the contract between the query and the screen that consumes its result.

Skills practised

  • Precisely define output columns
  • Respect the order requested by the recipient
  • Avoid SELECT* in a query intended for reuse

Available tables

Table produits

produits schema
ColumnTypeRole
id_produitINTEGERprimary key
produitVARCHARproduct name
categorieVARCHARfamily
prixDECIMALprice in TND
Sample data from produits
prixproduitcategorieid_produit
89KeyboardIT1
45MouseIT2
12NotebookOffice3

Your task

From the Products table, display the Product and Price columns, in that order.

Build your reasoning

  1. First locate the requested table: products.
  2. Transform each expected information into a column name: product then price.
  3. Place these columns after SELECT in the order of the expected result.
  4. Check that the query returns three rows and exactly two columns.
Query to complete
SELECT
  -- columns to choose
FROM produits;

Browser-based SQL environment

Interactive SQL editor

Run a read-only query on this exercise's fictional data. Nothing is sent to SQL.tn.

Local and private
Shortcut: Ctrl/⌘ + Enter
The SQL environment will be prepared when you first run the query.

Expected result

Expected result
produitprix
Keyboard89
Mouse45
Notebook12

Explained answer

Extra challenge

Extend the query

Add an alias prix_dt to the price column, then sort the products from most expensive to least expensive without adding a column to the result.