ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafywhere.htm

108 lines
7.1 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Specify a search condition using the WHERE clause" />
<meta name="abstract" content="The WHERE clause specifies a search condition that identifies the row or rows you want to retrieve, update, or delete." />
<meta name="description" content="The WHERE clause specifies a search condition that identifies the row or rows you want to retrieve, update, or delete." />
<meta name="DC.subject" content="SELECT statement, WHERE clause, description, clause, WHERE, example" />
<meta name="keywords" content="SELECT statement, WHERE clause, description, clause, WHERE, example" />
<meta name="DC.Relation" scheme="URI" content="rbafytexas.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafywhereexp.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafycompop.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafynotkwd.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafyussisql.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafycomsrch.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafymultiplewhere.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbafywhere" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Specify a search condition using the WHERE clause</title>
</head>
<body id="rbafywhere"><a name="rbafywhere"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Specify a search condition using the WHERE clause</h1>
<div><p>The WHERE clause specifies a search condition that identifies the
row or rows you want to retrieve, update, or delete.</p>
<div class="section"><p>The number of rows you process with an SQL statement then depends
on the number of rows that satisfy the WHERE clause <strong>search condition</strong>.
A search condition consists of one or more <strong>predicates</strong>. A predicate
specifies a test that you want SQL to apply to a specified row or rows of
a table. </p>
</div>
<div class="section"><p>In the following example, WORKDEPT = 'C01' is a predicate, WORKDEPT
and 'C01' are expressions, and the equal sign (=) is a comparison operator.
Note that character values are enclosed in apostrophes (<samp class="codeph">'</samp>);
numeric values are not. This applies to all constant values wherever they
are coded within an SQL statement. For example, to specify that you are interested
in the rows where the department number is C01, issue the following statement:</p>
<pre><strong>WHERE</strong> WORKDEPT = 'C01'</pre>
<p>In
this case, the search condition consists of one predicate: WORKDEPT = 'C01'.</p>
</div>
<div class="section"><p>To further illustrate WHERE, put it into a SELECT statement. Assume
that each department listed in the CORPDATA.DEPARTMENT table has a unique
department number. You want to retrieve the department name and manager number
from the CORPDATA.DEPARTMENT table for department C01. Issue the following
statement: </p>
<pre><strong>SELECT</strong> DEPTNAME, MGRNO
<strong>FROM</strong> CORPDATA.DEPARTMENT
<strong>WHERE</strong> DEPTNO = 'C01'</pre>
</div>
<div class="section"><p>When this statement is run, the result is one row: </p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="hsides" border="1" rules="all"><caption>Table 1. Result table</caption><thead align="left"><tr><th valign="top" id="d0e79">DEPTNAME</th>
<th valign="top" id="d0e81">MGRNO</th>
</tr>
</thead>
<tbody><tr><td valign="top" headers="d0e79 ">INFORMATION CENTER</td>
<td valign="top" headers="d0e81 ">000030</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section"><p>If the search condition contains character, or UCS-2 or UTF-16
graphic column predicates, the sort sequence that is in effect when the query
is run is applied to those predicates. If a sort sequence is not being used,
character constants must be specified in uppercase or lowercase to match the
column or expression they are being compared to.</p>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rbafywhereexp.htm">Expressions in the WHERE clause</a></strong><br />
An expression in a WHERE clause names or specifies something you want to compare to something else.</li>
<li class="ulchildlink"><strong><a href="rbafycompop.htm">Comparison operators</a></strong><br />
SQL supports these comparison operators.</li>
<li class="ulchildlink"><strong><a href="rbafynotkwd.htm">NOT keyword</a></strong><br />
You can precede a predicate with the NOT keyword to specify that you want the opposite of the predicate's value (that is, TRUE if the predicate is FALSE, or vice versa).</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafytexas.htm" title="Learn a variety of ways of tailoring your query to gather data using the SELECT statement. One way to do this is to use the SELECT statement in a program to retrieve a specific row (for example, the row for an employee). Furthermore, you can use clauses to gather data in a specific way.">Retrieve data using the SELECT statement</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="rbafyussisql.htm" title="A sort sequence defines how characters in a character set relate to each other when they are compared or ordered. Normalization allows you to compare strings that contain combining characters.">Sort sequences and normalization in SQL</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="rbafycomsrch.htm" title="In addition to the basic comparison predicates (=, &gt;, &lt;, and so on), a search condition can contain any of the predicates BETWEEN, IN, EXISTS, IS NULL, and LIKE.">Define complex search conditions</a></div>
<div><a href="rbafymultiplewhere.htm" title="You can qualify your request further by coding a search condition that includes several predicates.">Multiple search conditions within a WHERE clause</a></div>
</div>
</div>
</body>
</html>