Lesson 15 of 30Article11 min
SQL Operators & Comments
Arithmetic: +, -, *, / on numbers. Comparison: =, <>, >, <, >=, <=. Logical: AND, OR, NOT. Concatenation varies: || on PostgreSQL/SQLite, CONCAT() on MySQL, + on SQL Server.
Operators — arithmetic and comparison
Arithmetic: +, -, *, / on numbers. Comparison: =, <>, >, <, >=, <=. Logical: AND, OR, NOT. Concatenation varies: || on PostgreSQL/SQLite, CONCAT() on MySQL, + on SQL Server.
Real-life example: Operators are the math and logic symbols on a calculator — add credits, compare scores, combine filters.
Arithmetic and string concat
SELECT score, score + 5 AS curved_score FROM enrollments;
-- PostgreSQL / SQLite concat
SELECT full_name || ' (Grade ' || grade_level || ')' AS label FROM students;
-- MySQL concat
SELECT CONCAT(full_name, ' (Grade ', grade_level, ')') AS label FROM students;Comments — notes for humans
Single-line comments start with --. Multi-line comments use /* ... */. Comments do not run — they document your query.
Real-life example: Comments are pencil notes in the margin — 'only active students' — for the next person reading your SQL.
Single-line and multi-line comments
-- Top students in Delhi only
SELECT full_name, city
FROM students
WHERE city = 'Delhi'; /* change city as needed */
/*
Report: enrollments with scores
Author: analyst team
*/
SELECT * FROM enrollments WHERE score IS NOT NULL;