Condition (SQL)

Condition (SQL)

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 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

  1. ^ Fehily, Chris (2005). SQL: Visual Quickstart Guide (2 ed.). Peachpit Press. pp. 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." 

Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Condition — or Conditions may refer to: Contents 1 Logic 2 Computer programming 3 Other 4 See also Logic Logical conditional …   Wikipedia

  • SQL/PSM — stands for Structured Query Language/Persistent Stored Modules, and was developed by the American National Standards Institute (ANSI) as an extension to SQL. [ [http://www.itl.nist.gov/div897/ctg/dm/sql info.html NIST Article] ] It was first… …   Wikipedia

  • SQL — This article is about the database language. For the airport with IATA code SQL, see San Carlos Airport. SQL Paradigm(s) Multi paradigm Appeared in 1974 Designed by Donald D. Chamberlin Raymond F. Boyce Developer …   Wikipedia

  • SQL — Structured Query Language SQL Apparu en 1974 Auteur …   Wikipédia en Français

  • SQL Server — Microsoft SQL Server SQL Server Développeur Microsoft Dernière …   Wikipédia en Français

  • SQL Server 2000 — Microsoft SQL Server SQL Server Développeur Microsoft Dernière …   Wikipédia en Français

  • Microsoft SQL Server — SQL Server Développeur Microsoft Dernière version 2008 ( …   Wikipédia en Français

  • Join (SQL) — An SQL join clause combines records from two or more tables in a database.[1] It creates a set that can be saved as a table or used as is. A JOIN is a means for combining fields from two tables by using values common to each. ANSI standard SQL… …   Wikipedia

  • Delete (SQL) — In the database structured query language (SQL), the DELETE statement removes one or more records from a table. A subset may be defined for deletion using a condition, otherwise all records are removed.[1] Contents 1 Usage 2 Examples 3 …   Wikipedia

  • Merge (SQL) — A relational database management system uses SQL MERGE (upsert) statements to INSERT new records or UPDATE existing records depending on whether or not a condition matches. It was officially introduced in the SQL:2008 standard. Contents 1 Usage 2 …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”