SQL Comments & Operators

Annotate queries and calculate values.

✍️ 3 exercises + code challenge in this lesson

SQL Comments

  • Single line: -- comment
  • Multi-line: /* comment */

SQL Operators

  • Arithmetic: + - * / %
  • Comparison: = <> > < >= <=
  • Logical: AND OR NOT BETWEEN IN LIKE EXISTS IS NULL
  • String joining: || (standard, PostgreSQL, SQLite) or CONCAT() (MySQL, SQL Server)

Key Takeaways: SQL Comments & Operators

Mastering SQL Comments & Operators helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

SQL Comments & Operators Code Example

SQL
/* Price list with tax and discount */
SELECT ProductName,
       Price,
       Price * 0.18           AS Tax,      -- 18% sales tax
       Price * 1.18           AS WithTax,
       Stock % 2 = 0          AS EvenStock,
       'Item: ' || ProductName AS Label
FROM Products;
Free sign-in required · Google login available

SQL Comments & Operators Practice Exercises

Check what you learned in “SQL Comments & Operators”.

/ 3 solved
Fill in the blank

Write a single-line SQL comment.

 this query lists products
SELECT * FROM Products;
✓ Correct! Not quite. Try again.
Multiple choice

Which operator joins strings in standard SQL and SQLite?

✓ Correct! Not quite. Try again.
Code challenge

Select ProductName || ' (' || Category || ')' AS Label for ProductID 2.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services