Skip to content
AccountsISC Class 12 · Database Management System

SQL SELECT with WHERE, AND and OR: ISC Class 12 Accounts DBMS

Updated 17 October 2026 · Draft, not yet fact-checked

SQL SELECT retrieves data: SELECT column-list FROM table WHERE condition. The WHERE clause keeps only the rows for which the condition is true. AND needs both conditions true, OR needs at least one, and AND is evaluated before OR unless brackets are used. Text values go in single quotes, and a query returns the matching rows in the order stored unless an order is asked for.

AND narrows the result to the overlap, OR widens it to both circles, and AND is worked out before OR unless brackets are used.

Illustration drawn for QuestionBuddy.

Understand SQL: SELECT, WHERE, AND and OR

What SQL does. SQL (Structured Query Language) is the standard language for asking a relational database for data. The ISC syllabus asks for the basic commands Select, Where, And, Or (retrieval) here, and Update, Delete with the functions Avg, Count, Max, Min, Sum on the next topic page.

Sample tables used on this page and the next

Stock:

ItemCodeItemNameCategoryQtyRate
101PenStationery20010
102NotebookStationery15045
103StaplerStationery40120
104ChairFurniture251800
105TableFurniture104500
106PrinterElectronics58500
107MouseElectronics30350

Staff:

EmpIDNameDeptSalary
1AnilAccounts42000
2BeenaSales38000
3ChetanAccounts55000
4DeepaStores30000
5EshanSales47000
6FizaAccounts36000

Syntax

SELECT column1, column2 FROM table_name WHERE condition;
  • SELECT * returns every column.
  • FROM names the table.
  • WHERE filters rows. Without it, all rows come back.
  • A query ends with a semicolon.

Conditions. Use =, <>, <, >, <=, >=. Text and dates are written in single quotes ('Furniture'); numbers are not. Column names do not need quotes. Keywords are not case sensitive, but text values in quotes may be.

AND / OR. AND: both conditions must be true, so it narrows the result. OR: at least one must be true, so it widens the result. AND is evaluated before OR; use brackets to force the order you intend.

Calculated columns. An expression such as Qty * Rate can be selected; AS gives it a heading.

Reading a query. Go row by row: check each row against the WHERE condition and keep only those that are true; then show only the columns listed after SELECT.

Typical errors. Missing quotes around text; using = for text with the wrong spelling; mixing AND and OR without brackets; using a column that is not in the table.

SQL: SELECT, WHERE, AND and OR: key facts

Basic query
  • SELECT columns
  • FROM table
  • WHERE condition;
Order of clauses is fixed.
Comparison operators
  • = equal
  • <> not equal
  • < less
  • > greater
  • <= at most
  • >= at least
Text and dates in single quotes.
Logical operators
  • AND: both true
  • OR: at least one true
  • AND before OR
Brackets override the order.
Calculated column
An expression in the SELECT list, such as quantity multiplied by rate | AS gives the result a heading
The multiplication sign in SQL is the star.

How to answer SQL: SELECT, WHERE, AND and OR questions

Turn the English question into column list, table and condition.

  1. 1Identify the columns the question wants to see: that is the SELECT list.
  2. 2Name the table in FROM.
  3. 3Write each condition on its own and join them with AND or OR.
  4. 4Add brackets wherever AND and OR are mixed.
  5. 5Check the query row by row against the sample data to find the output.

SQL: SELECT, WHERE, AND and OR in real life

The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Asking the stock list a question

Suppose a school store keeps its items in the Stock table above and the storekeeper wants a list of stationery items costing more than ₹40.

Write the query and give the output.

Try it first, then show the solutionSolution
  1. Columns: ItemName; table: Stock.
  2. Conditions: Category = 'Stationery' AND Rate > 40.
  3. Rows meeting both: Notebook (45) and Stapler (120); Pen (10) fails the rate test.

Answer:

SELECT ItemName FROM Stock WHERE Category = 'Stationery' AND Rate > 40;
Output: Notebook, Stapler.

Memory hook: Every AND must pass; any OR is enough.

Tricks to remember SQL: SELECT, WHERE, AND and OR

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • S-F-W

    SELECT what, FROM where, WHERE which rows.

    Use it when: Clause order.

  • AND narrows, OR widens

    AND gives fewer rows; OR gives at least as many.

    Use it when: Predicting results.

  • AND first, then OR

    Like multiplication before addition, AND binds tighter than OR.

    Use it when: Precedence.

SQL: SELECT, WHERE, AND and OR: solved examples

Ordered from board level to HOTS. Try each one before you open the solution.

Example 1: The row-filtering clause · 1 mark · MCQBoard level

Which clause of a SELECT statement selects only the rows that satisfy a condition?
(a) FROM
(b) WHERE
(c) SELECT
(d) AND

Try it first, then show the solutionSolution
  1. FROM names the table and SELECT lists columns; WHERE filters rows.

Answer: (b) WHERE

Example 2: A simple query · 3 marks · Short answerBoard level

Write a query to display the name and rate of all items in the Furniture category from the Stock table, and give the output. (3 marks)

Try it first, then show the solutionSolution
  1. SELECT ItemName, Rate FROM Stock WHERE Category = 'Furniture';
  2. Rows with Furniture: Chair (1800) and Table (4500).

Answer:

SELECT ItemName, Rate FROM Stock WHERE Category = 'Furniture';
ItemNameRate
Chair1800
Table4500

Example 3: Five queries and their outputs · 6 marks · Long answerHarder board level

For the Stock table, give the output of: (a) SELECT * FROM Stock WHERE Qty < 30; (b) SELECT ItemName FROM Stock WHERE Category = 'Stationery' AND Rate > 40; (c) SELECT ItemName FROM Stock WHERE Category = 'Electronics' OR Rate > 4000; (d) SELECT ItemName, Qty * Rate AS Value FROM Stock WHERE Category = 'Stationery'; (e) SELECT ItemName, Qty FROM Stock WHERE (Category = 'Stationery' OR Category = 'Furniture') AND Qty >= 40; (6 marks)

Try it first, then show the solutionSolution
  1. (a) Qty below 30: Chair 25, Table 10, Printer 5 (Mouse has exactly 30, so it is excluded).
  2. (b) Stationery with Rate above 40: Notebook, Stapler.
  3. (c) Electronics or Rate above 4000: Table (4500), Printer, Mouse.
  4. (d) Value = Qty × Rate: Pen 200 × 10 = 2000; Notebook 150 × 45 = 6750; Stapler 40 × 120 = 4800.
  5. (e) Stationery or Furniture, with Qty at least 40: Pen 200, Notebook 150, Stapler 40.

Answer: (a)

ItemCodeItemNameCategoryQtyRate
104ChairFurniture251800
105TableFurniture104500
106PrinterElectronics58500

(b)
ItemName
Notebook
Stapler

(c)
ItemName
Table
Printer
Mouse

(d)
ItemNameValue
Pen2000
Notebook6750
Stapler4800

(e)
ItemNameQty
Pen200
Notebook150
Stapler40

Example 4: Precedence of AND and OR · 3 marks · Short answerHarder board level

Give the output of the two queries and explain the difference. Q1: SELECT ItemName FROM Stock WHERE Category = 'Furniture' OR Category = 'Electronics' AND Rate > 5000; Q2: SELECT ItemName FROM Stock WHERE (Category = 'Furniture' OR Category = 'Electronics') AND Rate > 5000; (3 marks)

Try it first, then show the solutionSolution
  1. Q1: AND is done first: Electronics AND Rate > 5000 is true only for Printer (8500). Then OR adds every Furniture item: Chair, Table, Printer.
  2. Q2: brackets make the category test first, then Rate > 5000 applies to both categories: only Printer.
  3. Hence Q1 returns 3 rows and Q2 returns 1.

Answer: Q1:

ItemName
Chair
Table
Printer

Q2:
ItemName
Printer

Example 5: Mixed conditions on the Staff table · 3 marks · Short answerHOTS / competency

A manager wants the Accounts staff earning more than ₹40,000 and also the Sales staff earning more than ₹40,000. A clerk writes: SELECT Name, Salary FROM Staff WHERE Dept = 'Accounts' AND Salary > 40000 OR Dept = 'Sales'; Give its output, explain the error and write the correct query with its output. (3 marks)

Try it first, then show the solutionSolution
  1. Clerk's query: AND first: Accounts staff over 40000 (Anil, Chetan) OR any Sales staff (Beena 38000, Eshan 47000): four rows. Beena earns only ₹38,000, so the result is wrong.
  2. Correct query: put the departments in brackets and apply the salary test to both: WHERE (Dept = 'Accounts' OR Dept = 'Sales') AND Salary > 40000.
  3. Output: Anil 42000, Chetan 55000, Eshan 47000.

Answer: Clerk's output:

NameSalary
Anil42000
Beena38000
Chetan55000
Eshan47000

Correct query:
SELECT Name, Salary FROM Staff WHERE (Dept = 'Accounts' OR Dept = 'Sales') AND Salary > 40000;
NameSalary
Anil42000
Chetan55000
Eshan47000

Where students lose marks in SQL: SELECT, WHERE, AND and OR

The slips examiners see most often, and what to write instead.

  • Mistake: Missing quotes around text

    Treating text as a column name.

    Wrong working

    WHERE Category = Furniture

    Right working

    WHERE Category = 'Furniture'

    Do this: Single quotes around text and dates.

    Usually costs: 1 mark.

  • Mistake: Mixing AND and OR without brackets

    Reading the query left to right.

    Wrong working

    Category = 'Furniture' OR Category = 'Electronics' AND Rate > 5000 meant as one group

    Right working

    (Category = 'Furniture' OR Category = 'Electronics') AND Rate > 5000

    Do this: Bracket the OR group.

    Usually costs: 1-2 marks.

  • Mistake: Using < instead of <=

    Careless with the boundary.

    Wrong working

    Qty < 30 expected to include Mouse

    Right working

    Qty <= 30 includes Mouse (Qty is exactly 30)

    Do this: Check the boundary rows.

    Usually costs: 1 mark.

  • Mistake: Writing columns in a wrong order in the output

    Copying the table instead of the SELECT list.

    Wrong working

    Output ItemName, Qty, Rate for SELECT ItemName, Qty * Rate

    Right working

    Output columns exactly as listed after SELECT

    Do this: Follow the SELECT list.

    Usually costs: 1 mark.

Exam tips

  • Show the query in capital keywords with a semicolon, then the output as a small table.
  • Mention the number of rows returned.
  • Test the boundary values in the sample data.
  • For mixed AND/OR, say which is evaluated first.

Practice questions on SQL: SELECT, WHERE, AND and OR

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQBoard level

    The query SELECT * FROM Staff; returns:
    (a) only the first row
    (b) all columns of all rows
    (c) only the column names
    (d) an error

    Hint

    The star means all columns.

    Answer

    (b) all columns of all rows

  2. Q2 · 3 marks · Short answerBoard level

    Using the Staff table, write a query to display the names of staff in the Sales department, and give the output. (3 marks)

    Hint

    Text is in single quotes.

    Answer
    SELECT Name FROM Staff WHERE Dept = 'Sales';

    Output: Beena, Eshan.

  3. Q3 · 3 marks · Short answerHarder board level

    Write a query to display the name and salary of staff whose salary is at least ₹36,000 and at most ₹45,000, and give the output. (3 marks)

    Hint

    Two conditions joined with AND.

    Answer
    SELECT Name, Salary FROM Staff WHERE Salary >= 36000 AND Salary <= 45000;
    NameSalary
    Anil42000
    Beena38000
    Fiza36000
  4. Q4 · 6 marks · Long answerHarder board level

    For the Staff table, write each query and give its output: (a) names of Accounts staff earning less than ₹40,000; (b) name and salary of staff in Stores or earning more than ₹50,000; (c) name and yearly salary (salary × 12) of Sales staff; (d) names of staff not in Accounts. (6 marks)

    Hint

    <> means not equal.

    Answer

    (a) SELECT Name FROM Staff WHERE Dept = 'Accounts' AND Salary < 40000; Output: Fiza.

    (b) SELECT Name, Salary FROM Staff WHERE Dept = 'Stores' OR Salary > 50000;

    NameSalary
    Chetan55000
    Deepa30000

    (c) SELECT Name, Salary * 12 AS Annual FROM Staff WHERE Dept = 'Sales';

    NameAnnual
    Beena456000
    Eshan564000

    (d) SELECT Name FROM Staff WHERE Dept <> 'Accounts'; Output: Beena, Deepa, Eshan.

  5. Q5 · 3 marks · Short answerHOTS / competency

    Predict the output of (i) SELECT Name FROM Staff WHERE Dept = 'Sales' OR Dept = 'Stores' AND Salary > 40000; and (ii) SELECT Name FROM Staff WHERE (Dept = 'Sales' OR Dept = 'Stores') AND Salary > 40000; and explain why they differ. (3 marks)

    Hint

    Beena earns 38,000.

    Answer

    (i) AND first: Stores staff over 40000 (none) OR all Sales staff: Beena, Eshan. (ii) Brackets: only Sales or Stores staff earning above 40000: Eshan. The brackets apply the salary test to both departments, so Beena (38,000) is dropped.

Test your recall

Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.

  1. 1.Which clause filters rows?Show answer

    WHERE.

  2. 2.What does SELECT * mean?Show answer

    Select all columns.

  3. 3.Which is evaluated first, AND or OR?Show answer

    AND.

  4. 4.How are text values written in SQL?Show answer

    In single quotes.

  5. 5.Which operator means not equal?Show answer

    <>.

SQL: SELECT, WHERE, AND and OR: frequently asked questions

Is SQL case sensitive?

Keywords are not; the text values inside quotes may be, depending on the system.

Do I need to write the output?

If the question gives a table and asks for the output, yes; show the heading and the matching rows.

What order are the rows in?

The order stored, unless the question asks for an ordering.

Do I need the semicolon?

Write it; it ends the statement.