Skip to content

Filtering with Exact Match — Precise Field Value Filtering

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you will learn about Filtering with Exact Match. We cover key concepts, practical examples, and best practices to help you master this topic.

Exact match filtering returns records where a field equals a specific value, using simple query parameters for precise data filtering.

Request Format

GET /api/users?role=admin
GET /api/products?category=electronics
GET /api/orders?status=shipped

Implementation

app.get("/api/users", async (req, res) => {
  const { role, status } = req.query;
  const conditions = [];
  const params = [];
  let idx = 1;

  if (role) {
    conditions.push(`role = $${idx++}`);
    params.push(role);
  }
  if (status) {
    conditions.push(`status = $${idx++}`);
    params.push(status);
  }

  const where = conditions.length
    ? `WHERE ${conditions.join(" AND ")}`
    : "";
  const result = await db.query(`SELECT * FROM users ${where}`, params);
  res.json({ data: result.rows });
});

Multiple Values

GET /api/users?role=admin,member
if (role) {
  const roles = role.split(",");
  const placeholders = roles.map(() => `$${idx++}`);
  conditions.push(`role IN (${placeholders.join(",")})`);
  params.push(...roles);
}

Common Mistakes

  1. Case-sensitive matching — Using = instead of ILIKE for case-insensitive text.
  2. No validation — Accepting invalid filter values that produce empty results.
  3. Over-filtering — Supporting too many filters that complicate queries.

Practice Questions

  1. How do you filter by single value?
  2. How do you filter by multiple values?
  3. Why validate filter values?

What's Next

In the next lesson, you will learn range filtering for numeric and date fields.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro