Condition (SQL)

From Wikipedia, the free encyclopedia
Jump to: navigation, search

A relational database management system uses SQL conditions or expressions in WHERE clauses and in HAVING clauses to SELECT subsets of data.

Types of condition[edit]

  • Many conditions compare values for (for example) equality, inequality or similarity.

Examples[edit]

To SELECT one row of data from a table called tab with a primary key column (pk) set to 100 — use the condition pk = 100:

SELECT * FROM tab WHERE pk = 100

To identify whether a table tab has rows of data with a duplicated key column dk set to 100 — use the condition dk = 100 and the condition having count(*) > 1:

SELECT * FROM tab WHERE dk = 100 having count(*) > 1

References[edit]

  1. ^ Fehily, Chris (2005). SQL: Visual Quickstart Guide (2 ed.). Peachpit Press. p. 480. ISBN 978-0-321-33417-6. "SQL Keywords [...] The appendix lists the SQL:2003 standard's reserved and non-reserved keywords. [...] EXISTS [...]" 
  2. ^ Fehily, Chris (2005). SQL: Visual Quickstart Guide (2 ed.). Peachpit Press. p. 278. ISBN 978-0-321-33417-6. "EXISTS and NOT EXISTS [...] look for the existence or nonexistence of rows in a subquery result."