ప్రధాన కంటెంట్‌కు వెళ్లండి
eLearner.app
మాడ్యూల్ 1 · 4లో పాఠం 3కోర్సులో 3/57~10 min
మాడ్యూల్ పాఠాలు (3/4)

WHEREతో ఫిల్టర్ చేస్తోంది

Often we do not need all the rows of a table, but only those that satisfy a certain condition. The WHERE clause filters rows based on a boolean expression:

SQL
SELECT <colonne>
FROM   <tabella>
WHERE  <condizione>;

The engine evaluates the condition one row at a time and keeps only those for which it returns TRUE.

Comparison operators

The most common ones are:

  • = equal, <> (or !=) not equal
  • <, <=, >, >=
  • BETWEEN a AND b — closed interval (a and b included)
  • IN (v1, v2, …) — membership in a list
  • LIKE 'patt%' — text matching with wildcard %

Text values are wrapped in single quotes: 'Milano'.

Combining conditions

You can combine multiple conditions with AND, OR and negate them with NOT. When mixing them, use parentheses for clarity:

SQL
WHERE department_id = 1
  AND (salary > 40000 OR hired_on < '2020-01-01');

Try it

వ్యాయామం#sql.m1.l3.e1
ప్రయత్నాలు: 0లోడ్ అవుతోంది...

Extract first name (first_name), last name (last_name) and salary (salary) of the employees with a salary strictly greater than 40,000.

ఎడిటర్ లోడ్ అవుతోంది…
సూచనను చూపించు

The condition you need is salary > 40000. Numbers do not require quotes.

3 ప్రయత్నాల తర్వాత పరిష్కారం లభిస్తుంది

Review exercise

వ్యాయామం#sql.m1.l3.e2
ప్రయత్నాలు: 0లోడ్ అవుతోంది...

Extract first name (first_name) and last name (last_name) of the employees whose last name starts with the letter 'R'. Use LIKE with the % wildcard.

ఎడిటర్ లోడ్ అవుతోంది…
సూచనను చూపించు

The pattern 'R%' means: strings that start with R followed by anything.

3 ప్రయత్నాల తర్వాత పరిష్కారం లభిస్తుంది