📄 subqueries.htm
字号:
<html>
<head>
<title>Subqueries</title>
</head>
<!--#include virtual="/inc/header.php"-->
<table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#FFFFFF">
<tr>
<td align="left">
<span style="font-family:Helvetica,Arial; font-size:12pt; color:#000000"><b>Subqueries
<br>
</b></span>
</td>
<td align="right">
<font face="Arial" size="2">
<a href="selectstatement.htm">Previous</a>
<a href="overview.htm">Top</a>
<a href="insertstatement.htm">Next</a>
</font>
</td>
</tr>
</table>
<br><br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
Absolute Database SQL Engine supports correlated and non-correlated subqueries in SELECT, UPDATE and DELETE statements.
<br>
You can use the following types of subqueris:
<br>
<br>
<b>Nested queries in the SELECT FROM clause
<br>
</b><span style="font-family:Helvetica,Arial; font-size:4pt; color:#000000"><b>
<br>
</b></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Usually SELECT uses tables to get records, but it is possible to use a subquery instead of a table.
<br>
</span><span style="font-family:Helvetica,Arial; font-size:4pt; color:#000000">
<br>
</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Example:</b>
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000"><span style="font-family:Courier New; font-size:8pt; color:#000080"><i>/* The subquery retrieves count of unique names in table "Employee", then function "count" counts quantity of these names.*/</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Courier New; font-size:10pt; color:#000000">SELECT COUNT(*) UniqueNamesCount FROM (SELECT DISTINCT FirstName FROM Employee)
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Courier New; font-size:10pt; color:#000000"></span></td></tr></table><span style="font-family:Courier New; font-size:10pt; color:#000000"></span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
<b>Subqueries in the WHERE clause
<br>
</b></span><span style="font-family:Helvetica,Arial; font-size:4pt; color:#000000">
<br>
</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">A subquery works like a search condition to restrict the number of rows returned by the outer, or "parent" query.
<br>
</span><span style="font-family:Helvetica,Arial; font-size:4pt; color:#000000">
<br>
</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><b>Examples:</b>
<br>
</span><span style="font-family:Helvetica,Arial; font-size:4pt; color:#000000">
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Helvetica,Arial; font-size:4pt; color:#000000"></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000"><span style="font-family:Courier New; font-size:8pt; color:#000080"><i>/* The query returns all venues where no event will take place. */</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Courier New; font-size:10pt; color:#000000">SELECT Venue FROM venues v WHERE NOT EXISTS (SELECT * FROM events WHERE VenueNo=v.VenueNo)</span><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span><span style="font-family:Helvetica,Arial; font-size:4pt; color:#000000">
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"></td><td><span style="font-family:Helvetica,Arial; font-size:4pt; color:#000000"></span></span><span style="font-family:Courier New; font-size:8pt; color:#000000"><span style="font-family:Courier New; font-size:8pt; color:#000080"><i>/* The query returns only those venues where some event will occur.*/</i></span></span><span style="font-family:Courier New; font-size:10pt; color:#000000">
<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -