Table

products

6 columns · 1 foreign keys · referenced by 1 tables

Columns

#NameTypeKey
01product_idSERIALPK
02nameVARCHAR(200)
03cat_idINTFK
04priceNUMERIC
05costNUMERIC
06stockINT

Outgoing references

  • cat_id — references another table

Referenced by

Example queries against this table

  1. Select first 5 products by price descending
    SQL
    SELECT product_id, name, price, stock
    FROM products
    ORDER BY price DESC
    LIMIT 5;
  2. Show total sum of all product prices in stock
    SQL
    SELECT
      SUM(price * stock) AS total_inventory_value
    FROM products
    WHERE is_active = TRUE;
  3. Show products with stock between 10 and 100
    SQL
    SELECT name, price, stock
    FROM products
    WHERE stock BETWEEN 10 AND 100
    ORDER BY stock;
  4. Show products with profit margin percentage
    SQL
    SELECT
      name,
      price,
      cost,
      ROUND((price - cost) / price * 100, 2) AS margin_pct
    FROM products
    WHERE cost IS NOT NULL AND cost > 0
    ORDER BY margin_pct DESC;