Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
queries-overview.html53 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>7.1. Overview</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="queries.html" title="Chapter 7. Queries" /><link rel="next" href="queries-table-expressions.html" title="7.2. Table Expressions" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">7.1. Overview</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="queries.html" title="Chapter 7. Queries">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="queries.html" title="Chapter 7. Queries">Up</a></td><th width="60%" align="center">Chapter 7. Queries</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="queries-table-expressions.html" title="7.2. Table Expressions">Next</a></td></tr></table><hr /></div><div class="sect1" id="QUERIES-OVERVIEW"><div class="titlepage"><div><div><h2 class="title" style="clear: both">7.1. Overview <a href="#QUERIES-OVERVIEW" class="id_link">#</a></h2></div></div></div><p>3   The process of retrieving or the command to retrieve data from a4   database is called a <em class="firstterm">query</em>.  In SQL the5   <a class="link" href="sql-select.html" title="SELECT"><code class="command">SELECT</code></a> command is6   used to specify queries.  The general syntax of the7   <code class="command">SELECT</code> command is8</p><pre class="synopsis">9[<span class="optional">WITH <em class="replaceable"><code>with_queries</code></em></span>] SELECT <em class="replaceable"><code>select_list</code></em> FROM <em class="replaceable"><code>table_expression</code></em> [<span class="optional"><em class="replaceable"><code>sort_specification</code></em></span>]10</pre><p>11   The following sections describe the details of the select list, the12   table expression, and the sort specification.  <code class="literal">WITH</code>13   queries are treated last since they are an advanced feature.14  </p><p>15   A simple kind of query has the form:16</p><pre class="programlisting">17SELECT * FROM table1;18</pre><p>19  Assuming that there is a table called <code class="literal">table1</code>,20  this command would retrieve all rows and all user-defined columns from21  <code class="literal">table1</code>.  (The method of retrieval depends on the22  client application.  For example, the23  <span class="application">psql</span> program will display an ASCII-art24  table on the screen, while client libraries will offer functions to25  extract individual values from the query result.)  The select list26  specification <code class="literal">*</code> means all columns that the table27  expression happens to provide.  A select list can also select a28  subset of the available columns or make calculations using the29  columns.  For example, if30  <code class="literal">table1</code> has columns named <code class="literal">a</code>,31  <code class="literal">b</code>, and <code class="literal">c</code> (and perhaps others) you can make32  the following query:33</p><pre class="programlisting">34SELECT a, b + c FROM table1;35</pre><p>36  (assuming that <code class="literal">b</code> and <code class="literal">c</code> are of a numerical37  data type).38  See <a class="xref" href="queries-select-lists.html" title="7.3. Select Lists">Section 7.3</a> for more details.39 </p><p>40  <code class="literal">FROM table1</code> is a simple kind of41  table expression: it reads just one table.  In general, table42  expressions can be complex constructs of base tables, joins, and43  subqueries.  But you can also omit the table expression entirely and44  use the <code class="command">SELECT</code> command as a calculator:45</p><pre class="programlisting">46SELECT 3 * 4;47</pre><p>48  This is more useful if the expressions in the select list return49  varying results.  For example, you could call a function this way:50</p><pre class="programlisting">51SELECT random();52</pre><p>53  </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="queries.html" title="Chapter 7. Queries">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="queries.html" title="Chapter 7. Queries">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="queries-table-expressions.html" title="7.2. Table Expressions">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 7. Queries </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 7.2. Table Expressions</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai