Languages

SQL Where

The WHERE clause is used for filtering rows.

Simplified syntax is:

SELECT column(s) FROM table WHERE column_name operator value

Standard SQL support these operators:

  • = equal
  • > greater than
  • < less than
  • >= greater than or equal
  • <= less than or equal
  • <> not equal to
  • LIKE search in texts
  • IN test whether value is from predefined list of values
  • BETWEEN if value is between two values

WHERE samples

You can try these commands in DatAdmin console. Try to modify it and see results

SELECT * FROM Customer WHERE Country = 'Germany'
SELECT * FROM Customer WHERE Email LIKE '%.de'
SELECT * FROM InvoiceLine WHERE UnitPrice > 1
SELECT * FROM Employee WHERE Employee.BirthDate BETWEEN '1970-01-01 00:00:00' AND '1980-01-01 00:00:00'
SELECT * FROM Customer WHERE Country IN ('Germany', 'Czech Republic')

Combining conditions

You can combine conditions using AND and OR conjuctions.

Last condition can be also with the some meaning rewritten as:

SELECT * FROM Employee WHERE Employee.BirthDate >= '1970-01-01 00:00:00' AND Employee.BirthDate <= '1980-01-01 00:00:00'

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options