Categories
  Encyclosphere.org ENCYCLOREADER
  supported by EncyclosphereKSF

Condition (SQL)

From HandWiki - Reading time: 1 min

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

  • Many conditions compare values for (for example) equality, inequality or similarity.
  • The EXISTS condition uses the SQL standard keyword EXISTS[1] to determine whether rows exist in a subquery result.[2]

Examples

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 column dk — use the condition having count(*) > 1:

SELECT dk FROM tab GROUP BY dk HAVING count(*) > 1


References

  1. Fehily, Chris (2005). SQL: Visual Quickstart Guide (2 ed.). Peachpit Press. pp. 439–440, 480. ISBN 978-0-321-33417-6. https://archive.org/details/sql0000fehi/page/439. "SQL Keywords [...] The appendix lists the 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. https://archive.org/details/sql0000fehi/page/278. "EXISTS and NOT EXISTS [...] look for the existence or nonexistence of rows in a subquery result." 




Licensed under CC BY-SA 3.0 | Source: https://handwiki.org/wiki/Condition_(SQL)
2 views | Status: cached on August 16 2024 19:24:40
↧ Download this article as ZWI file
Encyclosphere.org EncycloReader is supported by the EncyclosphereKSF