WHERE

更新时间:
复制 MD 格式

Overview

You can use WHERE clauses to select data from a table.

Syntax

select:
  SELECT [ DISTINCT ]
    { * | projectItem [, projectItem ]* }
  FROM tableExpression
    [ WHERE booleanExpression ]

The following table describes the types of booleanExpression.

No.

Expression type

Example

0

AND, OR

  1. WHERE a > 1 AND a < 100

  2. WHERE a > 5 OR c > 100

1

>, >=, <, <=, <>

2

IN

WHERE id IN (1, 2, 3, 4, 5)

3

User-defined functions (UDFs) (For more information, see Overview.)

  1. WHERE MATCHINDEX(brand, "Huawei")

  2. WHERE QUERY(brand, "Huawei OR OPPO")

  3. WHERE UDF(brand, "test") > 10

Examples

SELECT * FROM table WHERE f1 > 10 AND f2 < 5

SELECT * FROM table WHERE id IN (5, 6, 7, 8, 9)

Hint

You can use inverted indexes of Havenask to accelerate queries in WHERE clauses. For example, MATCHINDEX and QUERY are compatible with the syntax and equivalence conditions of Havenask queries, and equivalent conditions. Example: SELECT * FROM table WHERE f1 = 10. If f1 is used as an equivalent condition to create inverted indexes, the system can automatically optimize the query as an inverted query.