Skip
Arish's avatar

11. Less Than Operator


The Less Than Operator

The < operator finds values smaller than a specified number.

Syntax

sql
1SELECT * FROM table_name
2WHERE column < value;

Example: Young Students

Find students younger than 14:

sql
1SELECT * FROM students
2WHERE age < 14;

Result

idnameagecourse
2Bob12JavaScript
4David13Ruby
5Eve12Python

More Examples

sql
1-- Marks below 70
2SELECT * FROM students WHERE marks < 70;
3
4-- Students under 13
5SELECT * FROM students WHERE age < 13;
6
7-- Marks below passing (60)
8SELECT name, marks FROM students WHERE marks < 60;

With Strings (Alphabetical Order)

Less than works alphabetically with strings:

sql
1-- Names before 'D' alphabetically
2SELECT * FROM students WHERE name < 'D';

Returns: Alice, Bob, Carol (names starting with A, B, C)

Key Points

  1. < excludes the boundary value
  2. Works with numbers, dates, and strings
  3. For dates: earlier dates are "less than"
sql
1-- Orders before a date
2SELECT * FROM orders WHERE order_date < '2024-01-01';