Condition (SQL)
Encyclopedia
A relational database management system
uses SQL
conditions or expressions
in WHERE
clauses and in HAVING
clauses to SELECT
subsets of data.
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
Relational database management system
A relational database management system is a database management system that is based on the relational model as introduced by E. F. Codd. Most popular databases currently in use are based on the relational database model....
uses SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....
conditions or expressions
Expression (programming)
An expression in a programming language is a combination of explicit values, constants, variables, operators, and functions that are interpreted according to the particular rules of precedence and of association for a particular programming language, which computes and then produces another value...
in WHERE
Where (SQL)
A WHERE clause in SQL specifies that a SQL Data Manipulation Language statement should only affect rows that meet specified criteria. The criteria are expressed in the form of predicates...
clauses and in HAVING
Having (SQL)
A HAVING clause in SQL specifies that an SQL SELECT statement should only return rows where aggregate values meet the specified conditions. It was added to the SQL language because the WHERE keyword could not be used with aggregate functions.- Examples :...
clauses to SELECT
Select (SQL)
The SQL SELECT statement returns a result set of records from one or more tables.A SELECT statement retrieves zero or more rows from one or more database tables or database views. In most applications, SELECT is the most commonly used Data Manipulation Language command...
subsets of data.
Types of condition
- Many conditions compare values for (for example) equality, inequality or similarity.
- The EXISTS condition uses the SQL standardSQL:2003SQL:2003 is the fifth revision of the SQL database query language. The latest revision of the standard is SQL:2008.-Summary:The SQL:2003 standard makes minor modifications to all parts of SQL:1999 , and officially introduces a few new features such as:* XML-related features * Window functions* the...
keywordEXISTS
to determine whether rows exist in a subquery result.
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