<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Negar's tutorials and tips]]></title><description><![CDATA[Negar's tutorials and tips]]></description><link>https://khajeddin.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 16:28:45 GMT</lastBuildDate><atom:link href="https://khajeddin.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[PostgreSQL  - TABLE  Operations]]></title><description><![CDATA[Intro
Lets review all of the Table-related functions in one place.
Create tables in the database
Top create a table in your database use the CREATE TABLE command. Here, we define the schema of a table. We create users table which has two attributes/f...]]></description><link>https://khajeddin.com/postgresql-table-operations</link><guid isPermaLink="true">https://khajeddin.com/postgresql-table-operations</guid><category><![CDATA[SQL]]></category><category><![CDATA[Databases]]></category><category><![CDATA[PostgreSQL]]></category><category><![CDATA[crud]]></category><category><![CDATA[CRUD Operations]]></category><category><![CDATA[table]]></category><dc:creator><![CDATA[Negar]]></dc:creator><pubDate>Thu, 01 Feb 2024 01:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1706787985274/c07c91fe-b94f-4e0f-a724-777f1f9ec7bf.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-intro">Intro</h2>
<p>Lets review all of the Table-related functions in one place.</p>
<h3 id="heading-create-tables-in-the-database">Create tables in the database</h3>
<p>Top create a table in your database use the <code>CREATE TABLE</code> command. Here, we define the schema of a table. We create <em>users</em> table which has two attributes/fields/columns, <em>name</em> and <em>email</em>. Each of these attributes are defined as character strings with max of 128 characters</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> users(
people(&gt; <span class="hljs-type">name</span> <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">128</span>),
people(&gt; email <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">128</span>)
people(&gt; );
<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span>
people=&gt;
</code></pre>
<h3 id="heading-list-tables-in-the-database">List tables in the database</h3>
<p>To list tables/relations in the database use to he following command:</p>
<pre><code class="lang-pgsql">people=&gt; \dt
Did <span class="hljs-keyword">not</span> find <span class="hljs-keyword">any</span> relations.
</code></pre>
<p>if you haven't created any tables in your database yet, you will get "Did not find any relations." message. Otherwise, you will get list of existing tables like what follows:</p>
<pre><code class="lang-pgsql">people=&gt; \dt
       List <span class="hljs-keyword">of</span> relations
 <span class="hljs-keyword">Schema</span> | <span class="hljs-type">Name</span>  | <span class="hljs-keyword">Type</span>  | <span class="hljs-keyword">Owner</span>
<span class="hljs-comment">--------+-------+-------+-------</span>
 <span class="hljs-built_in">public</span> | users | <span class="hljs-keyword">table</span> | pg4e
(<span class="hljs-number">1</span> <span class="hljs-keyword">row</span>)

people=&gt;
</code></pre>
<h3 id="heading-get-the-schema-of-a-table">Get the schema of a table</h3>
<p>Lets suppose we have forgotten what was the schema (the definition of the table and its attributes/columns), and we want to review the schema one more time. In this case we can use the following command:</p>
<pre><code class="lang-pgsql">people=&gt; \d+ users
                                                  <span class="hljs-keyword">Table</span> "public.users"
 <span class="hljs-keyword">Column</span> |          <span class="hljs-keyword">Type</span>          | <span class="hljs-keyword">Collation</span> | Nullable | <span class="hljs-keyword">Default</span> | <span class="hljs-keyword">Storage</span>  | Compression | Stats target | Description
<span class="hljs-comment">--------+------------------------+-----------+----------+---------+----------+-------------+--------------+-------------</span>
 <span class="hljs-type">name</span>   | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
 email  | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
<span class="hljs-keyword">Access</span> <span class="hljs-keyword">method</span>: heap

people=&gt;
</code></pre>
<h2 id="heading-basic-crud-commands">Basic CRUD commands</h2>
<h3 id="heading-insertcreate-rows-into-the-table">INSERT/create row(s) into the table</h3>
<p>Suppose we wan to insert several rows/objects into the table. We have to use the following command:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (<span class="hljs-type">name</span>, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'Peter'</span>, <span class="hljs-string">'peter@example.edu'</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-number">0</span> <span class="hljs-number">1</span>
people=&gt; <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (<span class="hljs-type">name</span>, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'Terry'</span>, <span class="hljs-string">'terry@example.edu'</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-number">0</span> <span class="hljs-number">1</span>
people=&gt; <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (<span class="hljs-type">name</span>, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'Eliza'</span>, <span class="hljs-string">'eliza@example.edu'</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-number">0</span> <span class="hljs-number">1</span>
people=&gt; <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (<span class="hljs-type">name</span>, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'John'</span>, <span class="hljs-string">'john@example.edu'</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-number">0</span> <span class="hljs-number">1</span>
</code></pre>
<h3 id="heading-readselect-rows-from-a-table">READ/SELECT row(s) from a table</h3>
<p>In order to read the rows in a table we should use <code>SELECT</code> command:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
 <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">-------+-------------------</span>
 Peter | peter@example.edu
 Terry | terry@example.edu
 Eliza | eliza@example.edu
 John  | john@example.edu
(<span class="hljs-number">4</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<p>We can include some criteria in the SELECT command as well:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">WHERE</span> email=<span class="hljs-string">'terry@example.edu'</span>;
 <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">-------+-------------------</span>
 Terry | terry@example.edu
(<span class="hljs-number">1</span> <span class="hljs-keyword">row</span>)
</code></pre>
<h3 id="heading-update-rows-in-a-table">UPDATE row(s) in a table</h3>
<p>In order to update one/more piece(s) of information in one/more row(s), we use <code>UPDATE</code> command like what follows:</p>
<pre><code class="lang-pgsql">people-&gt; <span class="hljs-keyword">UPDATE</span> users <span class="hljs-keyword">SET</span> <span class="hljs-type">name</span>=<span class="hljs-string">'Johnny'</span> <span class="hljs-keyword">WHERE</span> email=<span class="hljs-string">'john@example.edu'</span>;
<span class="hljs-keyword">UPDATE</span> <span class="hljs-number">1</span>
</code></pre>
<p><strong>Hint: this command will update any number of rows that meet its criteria.</strong></p>
<p>Lets see how this command changed the last entry of <em>users</em> table:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Peter  | peter@example.edu
 Terry  | terry@example.edu
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
(<span class="hljs-number">4</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h3 id="heading-delete-rows-from-a-table">DELETE row(s) from a table</h3>
<p>To remove one/more row(s) from a table, use the DELETE command like what follows:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">DELETE</span> <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">WHERE</span> email=<span class="hljs-string">'terry@example.edu'</span>;
<span class="hljs-keyword">DELETE</span> <span class="hljs-number">1</span>
</code></pre>
<p><strong>Hint: this command will delete any number of rows that meet its criteria.</strong></p>
<p>Lets see how this command removed an entry of <em>users</em> table:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Peter  | peter@example.edu
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
(<span class="hljs-number">3</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h2 id="heading-alter-table">ALTER TABLE</h2>
<p>What happens if you missed something in the time of creation of a table in database? Is it over? ABSOLUTELY NOT! SQL lets us change the table schema in the times needed.</p>
<p>When you use <code>ALTER TABLE</code> and change the definition of one field, a SQL-based database applies that change to both the table's schema and to all of the existing data in that table, all while the system is running and functional. So there are a couple of actions like add, change, drop a column that you can do using <code>ALTER TABLE</code> key words. Lets suppose that we have created the following table and we want to make changes to this table.</p>
<pre><code class="lang-plaintext">CREATE TABLE users(
name VARCHAR(128),
email VARCHAR(128)
);
</code></pre>
<p>First, lets take a look at the table's schema:</p>
<pre><code class="lang-pgsql">people=# \d+ users
                                                  <span class="hljs-keyword">Table</span> "public.users"
 <span class="hljs-keyword">Column</span> |          <span class="hljs-keyword">Type</span>          | <span class="hljs-keyword">Collation</span> | Nullable | <span class="hljs-keyword">Default</span> | <span class="hljs-keyword">Storage</span>  | Compression | Stats target | Description
<span class="hljs-comment">--------+------------------------+-----------+----------+---------+----------+-------------+--------------+-------------</span>
 <span class="hljs-type">name</span>   | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
 email  | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
<span class="hljs-keyword">Access</span> <span class="hljs-keyword">method</span>: heap
</code></pre>
<h3 id="heading-add-a-column-to-a-table">Add a column to a table</h3>
<p>In order to add a column with " <code>address VARCHAR(128)</code> " definition to the <em>users</em> table, we have to use the following code. You can see the changes into the table's schema</p>
<pre><code class="lang-pgsql">people=# <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> users <span class="hljs-keyword">ADD</span> <span class="hljs-keyword">COLUMN</span> address <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">128</span>);
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span>

people=# \d+ users
                                                  <span class="hljs-keyword">Table</span> "public.users"
 <span class="hljs-keyword">Column</span>  |          <span class="hljs-keyword">Type</span>          | <span class="hljs-keyword">Collation</span> | Nullable | <span class="hljs-keyword">Default</span> | <span class="hljs-keyword">Storage</span>  | Compression | Stats target | Description
<span class="hljs-comment">---------+------------------------+-----------+----------+---------+----------+-------------+--------------+-------------</span>
 <span class="hljs-type">name</span>    | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
 email   | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
 address | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
<span class="hljs-keyword">Access</span> <span class="hljs-keyword">method</span>: heap
</code></pre>
<h3 id="heading-change-type-of-a-column">Change type of a column</h3>
<p>To change type of <em>address</em> column from <code>VARCHAR(128)</code> to <code>TEXT</code>, we have to use to following code:</p>
<pre><code class="lang-pgsql">people=# <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> users <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">COLUMN</span> address <span class="hljs-keyword">TYPE</span> <span class="hljs-type">TEXT</span>;
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span>
people=# \d+ users
                                                  <span class="hljs-keyword">Table</span> "public.users"
 <span class="hljs-keyword">Column</span>  |          <span class="hljs-keyword">Type</span>          | <span class="hljs-keyword">Collation</span> | Nullable | <span class="hljs-keyword">Default</span> | <span class="hljs-keyword">Storage</span>  | Compression | Stats target | Description
<span class="hljs-comment">---------+------------------------+-----------+----------+---------+----------+-------------+--------------+-------------</span>
 <span class="hljs-type">name</span>    | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
 email   | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
 address | <span class="hljs-type">text</span>                   |           |          |         | extended |             |              |
<span class="hljs-keyword">Access</span> <span class="hljs-keyword">method</span>: heap
</code></pre>
<h3 id="heading-drop-a-column-of-a-table">Drop a column of a table</h3>
<p>In order to drop the address column of users table, we have to use the following code:</p>
<pre><code class="lang-pgsql">people=# <span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> users <span class="hljs-keyword">DROP</span> address;
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span>
people=# \d+ users
                                                  <span class="hljs-keyword">Table</span> "public.users"
 <span class="hljs-keyword">Column</span> |          <span class="hljs-keyword">Type</span>          | <span class="hljs-keyword">Collation</span> | Nullable | <span class="hljs-keyword">Default</span> | <span class="hljs-keyword">Storage</span>  | Compression | Stats target | Description
<span class="hljs-comment">--------+------------------------+-----------+----------+---------+----------+-------------+--------------+-------------</span>
 <span class="hljs-type">name</span>   | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
 email  | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
<span class="hljs-keyword">Access</span> <span class="hljs-keyword">method</span>: heap
</code></pre>
<h2 id="heading-update">UPDATE</h2>
<p>What happens if we wanted to update content of one/several row(s)? In this case we can you <code>UPDATE</code> key word.</p>
<h3 id="heading-update-content-of-rows-in-a-table">Update content of row(s) in a table</h3>
<p>First Lets take a look at the current contents of the <em>users</em> table:</p>
<pre><code class="lang-pgsql">people=# <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Peter  | peter@example.edu
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
 Terry  | terry@example.edu
(<span class="hljs-number">4</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<p>Now, lets change the email address of the user named Johnny, and watch the results:</p>
<pre><code class="lang-pgsql">people=# <span class="hljs-keyword">UPDATE</span> users <span class="hljs-keyword">SET</span> email=<span class="hljs-string">'johnny@example.edu'</span> <span class="hljs-keyword">WHERE</span> <span class="hljs-type">name</span>=<span class="hljs-string">'johnny'</span>;
<span class="hljs-keyword">UPDATE</span> <span class="hljs-number">1</span>
people=# <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+--------------------</span>
 Peter  | peter@example.edu
 Eliza  | eliza@example.edu
 Terry  | terry@example.edu
 Johnny | johnny@example.edu
(<span class="hljs-number">4</span> <span class="hljs-keyword">rows</span>)
</code></pre>
]]></content:encoded></item><item><title><![CDATA[SQL (Structured Query Language) Introduction]]></title><description><![CDATA[In order to become familiar with SQL and SQL-based platforms, one have to gain basic knowledge about some of the basic concepts. Here I will list what seems to be to be important to know before jumping to learn any SQL-based platform. These concepts ...]]></description><link>https://khajeddin.com/sql-structured-query-language-introduction</link><guid isPermaLink="true">https://khajeddin.com/sql-structured-query-language-introduction</guid><category><![CDATA[into_to_SQL]]></category><category><![CDATA[SQL]]></category><category><![CDATA[Databases]]></category><category><![CDATA[PostgreSQL]]></category><category><![CDATA[Relational Database]]></category><category><![CDATA[sql architecture]]></category><category><![CDATA[#SQL-basic]]></category><dc:creator><![CDATA[Negar]]></dc:creator><pubDate>Tue, 23 Jan 2024 01:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1706004241214/8f387d82-ca7a-47ab-9a1f-4cc2f124bf5b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In order to become familiar with SQL and SQL-based platforms, one have to gain basic knowledge about some of the basic concepts. Here I will list what seems to be to be important to know before jumping to learn any SQL-based platform. These concepts helps you to have a big picture about what you are about to learn and why you need to use them. Of course, I might change this list over the time as I myself gain more and more experienced in teaching SQL. For some the following concepts I have written a small description and for others I don't; anyway, this is to provide a checklist for your start point, not to provide you with extensive definitions. I'm sure you can find many comprehensive definitions using search engines and generative AI tools.</p>
<p>Important basic have-to-knows before learning SQL:</p>
<ol>
<li><p>What are Database?</p>
</li>
<li><p>What is a Relational Database?</p>
</li>
<li><p>What is SQL (Structured Query Language)?</p>
</li>
<li><p>What are the most popular SQL-Based Databases?</p>
<ul>
<li><p>MySQL:Fast and scalable, Commercial Open Source.</p>
</li>
<li><p>Oracle: Commercial, Enterprise-Scale.</p>
</li>
<li><p>MariaDB: Open Source.</p>
</li>
<li><p>PostgreSQL: Opensource.</p>
</li>
<li><p>Some other smaller projects like: SQLite, HSQL, ...</p>
</li>
</ul>
</li>
<li><p>What does CRUD (Create, Read/Select, Update, Delete) mean?</p>
<p> The four basic actions that one can do using databases are:</p>
<ul>
<li><p>Creating/Inserting Data</p>
</li>
<li><p>Read/Select some Data</p>
</li>
<li><p>Update Data</p>
</li>
<li><p>Delete Data</p>
</li>
</ul>
</li>
<li><p>In a Relational Database, what does a Database represent?</p>
<p> It contains one or more tables.</p>
</li>
<li><p>In a Relational Database, what does a Relation/Tuple represent?</p>
<p> It contains tuples and attributes.</p>
</li>
<li><p>In a Relational Database, what does a Tuple/Row represent?</p>
<p> a set of fields which generally represent an "Object", like a person or a music track</p>
</li>
<li><p>In a Relational Database, what does an Attribute/Column/Field represent?</p>
<p> One pf the possible many elements of data corresponding to the object represented by the row</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705998248205/1bc877f1-b873-417e-a20b-5a410198cd65.png" alt="Image from https://en.wikipedia.org/wiki/Relational_database" class="image--center mx-auto" /></p>
</li>
<li><p>What is a Database Schema?</p>
</li>
<li><p>What is the SQL Architecture? How SQL commands are run on a SQL Server (regardless of what kind of SQL Client and/or Server you are using)?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705999167044/d618c7d2-97b5-4839-8fe9-2c4d8a45e4d9.png" alt="Picture from &quot;Database Design and Basic SQL in PostgreSQL&quot; coursera course&gt;Week1&gt;&quot;SQL Architeture&quot;" class="image--center mx-auto" /></p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[PostgreSQL Basics]]></title><description><![CDATA[Install PostgreSQL on your system. you can find the installers for various platforms in this link.
Difference between PSQL and SQL commands
First of all, lets differentiate between PostgreSQL and SQL commands:

Any command starting with backslash \ i...]]></description><link>https://khajeddin.com/postgresql-basics</link><guid isPermaLink="true">https://khajeddin.com/postgresql-basics</guid><category><![CDATA[PostgreSQL]]></category><category><![CDATA[psql]]></category><dc:creator><![CDATA[Negar]]></dc:creator><pubDate>Tue, 23 Jan 2024 01:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1706072517096/30c87f0e-f2e4-4ebe-8735-4119db38ab05.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Install PostgreSQL on your system. you can find the installers for various platforms in this <a target="_blank" href="https://www.postgresql.org/download/">link</a>.</p>
<h2 id="heading-difference-between-psql-and-sql-commands">Difference between PSQL and SQL commands</h2>
<p>First of all, lets differentiate between PostgreSQL and SQL commands:</p>
<ul>
<li><p>Any command starting with backslash <code>\</code> is a PostgreSQL command.</p>
<p>  For example, commands like getting a list of databases <code>\l</code>, getting a list of tables <code>\dt</code>, getting a table schema <code>\d+ &lt;TableName&gt;</code> and so forth are all PostgreSQL commands since they are starting with <code>\</code></p>
</li>
<li><p>otherwise, its SQL command.</p>
<p>  For Instance, commands like <code>SELECT FROM &lt;TableName&gt;</code><em>,</em> <code>DROP TABLE &lt;TableName&gt;</code><em>,</em> <code>DELETE * FROM &lt;TableName&gt; WHERE &lt;ConditionDescription&gt;</code> and so forth are all SQL command.</p>
</li>
<li><p>Since here we are using PSQL client, any command that starts with <code>psql</code> mean that we are asking the client to do some task. Therefore, If you are using another client, you should substitute <code>psql</code> part of that command with the name of your PSQL client.</p>
</li>
</ul>
<p>In what follows, I won't explicitly state whether a command is a PSQL or SQL one.</p>
<h2 id="heading-disconnecting-to-databases">(Dis)Connecting to databases</h2>
<h3 id="heading-connect-to-the-default-database">Connect to the default database</h3>
<p>After Installation is completed, connect to the default server using the following commands:</p>
<pre><code class="lang-pgsql">C:\&gt;psql -U postgres
psql (<span class="hljs-number">16.1</span>)
<span class="hljs-built_in">WARNING</span>: Console code page (<span class="hljs-number">850</span>) differs <span class="hljs-keyword">from</span> Windows code page (<span class="hljs-number">1252</span>)
         <span class="hljs-number">8</span>-<span class="hljs-type">bit</span> characters might <span class="hljs-keyword">not</span> <span class="hljs-keyword">work</span> correctly. See psql reference
         page "Notes for Windows users" <span class="hljs-keyword">for</span> details.
<span class="hljs-keyword">Type</span> "help" <span class="hljs-keyword">for</span> help.

postgres=#
</code></pre>
<p>The <code>postgres=#</code> prompt show that we have connected to the "postgres" database, and the <code>#</code> shows that we have connected to this database with a <strong>superuser</strong> user.</p>
<h3 id="heading-connect-to-another-specific-database">Connect to another specific database</h3>
<p>To connect to any database we should use <code>psql</code> command.</p>
<p><code>-d DatabaseName</code> : The first parameter of this command is "database name"</p>
<p><code>-U DatabaseUser</code> : The second parameter is name of the user with whom credentials' we want to connect to the database.</p>
<p><code>-W</code> : push the server to ask for password</p>
<pre><code class="lang-pgsql">C:\&gt;psql -d people -U pg4e -W
<span class="hljs-keyword">Password</span>:
psql (<span class="hljs-number">16.1</span>)
<span class="hljs-built_in">WARNING</span>: Console code page (<span class="hljs-number">850</span>) differs <span class="hljs-keyword">from</span> Windows code page (<span class="hljs-number">1252</span>)
         <span class="hljs-number">8</span>-<span class="hljs-type">bit</span> characters might <span class="hljs-keyword">not</span> <span class="hljs-keyword">work</span> correctly. See psql reference
         page "Notes for Windows users" <span class="hljs-keyword">for</span> details.
<span class="hljs-keyword">Type</span> "help" <span class="hljs-keyword">for</span> help.

people=&gt;
</code></pre>
<p>The <code>people=&gt;</code> prompt show that we have connected to the "people" database, and the <code>&gt;</code> shows that we have connected to this database with a <strong>non-superuser</strong> user.</p>
<h3 id="heading-connecting-to-a-database-on-another-host">Connecting to a database on another host</h3>
<p>To connect to any database on another host we should use the following command:</p>
<p><code>-h &lt;HostAddress&gt;</code> : Specifies Address of the host on which the database is.</p>
<p><code>-p &lt;PortNumber&gt;</code> : Specifies the port number to connect to that host</p>
<p><code>-d &lt;DatabaseName&gt;</code> : Specifies "database name"</p>
<p><code>-U &lt;DatabaseUser&gt;</code> : Specifies name of the user with whom credentials' we want to connect to the database.</p>
<p><code>-W</code> : push the server to ask for password</p>
<pre><code class="lang-pgsql">C:\&gt;psql -h example.com -p <span class="hljs-number">5432</span> -d people -U pg4e -W
<span class="hljs-keyword">Password</span>:
psql (<span class="hljs-number">16.1</span>)
<span class="hljs-built_in">WARNING</span>: Console code page (<span class="hljs-number">850</span>) differs <span class="hljs-keyword">from</span> Windows code page (<span class="hljs-number">1252</span>)
         <span class="hljs-number">8</span>-<span class="hljs-type">bit</span> characters might <span class="hljs-keyword">not</span> <span class="hljs-keyword">work</span> correctly. See psql reference
         page "Notes for Windows users" <span class="hljs-keyword">for</span> details.
<span class="hljs-keyword">Type</span> "help" <span class="hljs-keyword">for</span> help.

people=&gt;
</code></pre>
<p>The <code>people=&gt;</code> prompt show that we have connected to the "people" database, and the <code>&gt;</code> shows that we have connected to this database with a <strong>non-superuser</strong> user.</p>
<h3 id="heading-disconnect-quit-a-session">Disconnect (quit) a session</h3>
<p>In order to quit an PostgreSQL session use the following command:</p>
<pre><code class="lang-pgsql">postgres=# \q
</code></pre>
<h2 id="heading-creating-and-listing-database-table-and-user">Creating and listing database, table and user</h2>
<h3 id="heading-get-the-database-version">Get the database version</h3>
<p>Lest get the version of you PostgreSQL database:</p>
<pre><code class="lang-pgsql"><span class="hljs-keyword">SELECT</span> version();
</code></pre>
<h3 id="heading-get-list-of-databases">Get list of databases</h3>
<p>Now get list of default databases created by the installer while installing the PostgreSQL database:</p>
<pre><code class="lang-pgsql">postgres=# \l
                                                                      List <span class="hljs-keyword">of</span> databases
   <span class="hljs-type">Name</span>    |  <span class="hljs-keyword">Owner</span>   | <span class="hljs-keyword">Encoding</span> | Locale Provider |          <span class="hljs-keyword">Collate</span>           |           Ctype            | ICU Locale | ICU Rules |   <span class="hljs-keyword">Access</span> <span class="hljs-keyword">privileges</span>
<span class="hljs-comment">-----------+----------+----------+-----------------+----------------------------+----------------------------+------------+-----------+-----------------------</span>
 postgres  | postgres | UTF8     | libc            | English_United States<span class="hljs-number">.1252</span> | English_United States<span class="hljs-number">.1252</span> |            |           |
 template0 | postgres | UTF8     | libc            | English_United States<span class="hljs-number">.1252</span> | English_United States<span class="hljs-number">.1252</span> |            |           | =c/postgres          +
           |          |          |                 |                            |                            |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | English_United States<span class="hljs-number">.1252</span> | English_United States<span class="hljs-number">.1252</span> |            |           | =c/postgres          +
           |          |          |                 |                            |                            |            |           | postgres=CTc/postgres
(<span class="hljs-number">3</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h3 id="heading-create-a-new-database">Create a new Database</h3>
<p>Use the following command to create a database named "people" whose owner is "pg4e" user:</p>
<pre><code class="lang-pgsql">postgres=# <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">DATABASE</span> people <span class="hljs-keyword">WITH</span> <span class="hljs-keyword">OWNER</span> <span class="hljs-string">'pg4e'</span>;
<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">DATABASE</span>
</code></pre>
<h3 id="heading-create-a-new-non-superuser-user">Create a new non-superuser User</h3>
<p>Use the Following command to create a user named "pg4e" with password "secret"</p>
<pre><code class="lang-pgsql">postgres=# <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">USER</span> pg4e <span class="hljs-keyword">WITH</span> <span class="hljs-keyword">PASSWORD</span> <span class="hljs-string">'secret'</span>;
<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">ROLE</span>
</code></pre>
<h3 id="heading-create-tables-in-the-database">Create tables in the database</h3>
<p>Top create a table in your database use the <code>CREATE TABLE</code> command. Here, we define the schema of a table. We create <em>users</em> table which has two attributes/fields/columns, <em>name</em> and <em>email</em>. Each of these attributes are defined as character strings with max of 128 characters</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> users(
people(&gt; <span class="hljs-type">name</span> <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">128</span>),
people(&gt; email <span class="hljs-type">VARCHAR</span>(<span class="hljs-number">128</span>)
people(&gt; );
<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span>
people=&gt;
</code></pre>
<h3 id="heading-list-tables-in-the-database">List tables in the database</h3>
<p>To list tables/relations in the database use to he following command:</p>
<pre><code class="lang-pgsql">people=&gt; \dt
Did <span class="hljs-keyword">not</span> find <span class="hljs-keyword">any</span> relations.
</code></pre>
<p>if you haven't created any tables in your database yet, you will get "Did not find any relations." message. Otherwise, you will get list of existing tables like what follows:</p>
<pre><code class="lang-pgsql">people=&gt; \dt
       List <span class="hljs-keyword">of</span> relations
 <span class="hljs-keyword">Schema</span> | <span class="hljs-type">Name</span>  | <span class="hljs-keyword">Type</span>  | <span class="hljs-keyword">Owner</span>
<span class="hljs-comment">--------+-------+-------+-------</span>
 <span class="hljs-built_in">public</span> | users | <span class="hljs-keyword">table</span> | pg4e
(<span class="hljs-number">1</span> <span class="hljs-keyword">row</span>)

people=&gt;
</code></pre>
<h3 id="heading-get-the-schema-of-a-table">Get the schema of a table</h3>
<p>Lets suppose we have forgotten what was the schema (the definition of the table and its attributes/columns), and we want to review the schema one more time. In this case we can use the following command:</p>
<pre><code class="lang-pgsql">people=&gt; \d+ users
                                                  <span class="hljs-keyword">Table</span> "public.users"
 <span class="hljs-keyword">Column</span> |          <span class="hljs-keyword">Type</span>          | <span class="hljs-keyword">Collation</span> | Nullable | <span class="hljs-keyword">Default</span> | <span class="hljs-keyword">Storage</span>  | Compression | Stats target | Description
<span class="hljs-comment">--------+------------------------+-----------+----------+---------+----------+-------------+--------------+-------------</span>
 <span class="hljs-type">name</span>   | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
 email  | <span class="hljs-type">character</span> <span class="hljs-type">varying</span>(<span class="hljs-number">128</span>) |           |          |         | extended |             |              |
<span class="hljs-keyword">Access</span> <span class="hljs-keyword">method</span>: heap

people=&gt;
</code></pre>
<h2 id="heading-basic-crud-commands">Basic CRUD commands</h2>
<h3 id="heading-insertcreate-rows-into-the-table">INSERT/create row(s) into the table</h3>
<p>Suppose we wan to insert several rows/objects into the table. We have to use the following command:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (<span class="hljs-type">name</span>, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'Peter'</span>, <span class="hljs-string">'peter@example.edu'</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-number">0</span> <span class="hljs-number">1</span>
people=&gt; <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (<span class="hljs-type">name</span>, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'Terry'</span>, <span class="hljs-string">'terry@example.edu'</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-number">0</span> <span class="hljs-number">1</span>
people=&gt; <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (<span class="hljs-type">name</span>, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'Eliza'</span>, <span class="hljs-string">'eliza@example.edu'</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-number">0</span> <span class="hljs-number">1</span>
people=&gt; <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> users (<span class="hljs-type">name</span>, email) <span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'John'</span>, <span class="hljs-string">'john@example.edu'</span>);
<span class="hljs-keyword">INSERT</span> <span class="hljs-number">0</span> <span class="hljs-number">1</span>
</code></pre>
<h3 id="heading-readselect-rows-from-a-table">READ/SELECT row(s) from a table</h3>
<p>In order to read the rows in a table we should use <code>SELECT</code> command:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
 <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">-------+-------------------</span>
 Peter | peter@example.edu
 Terry | terry@example.edu
 Eliza | eliza@example.edu
 John  | john@example.edu
(<span class="hljs-number">4</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<p>We can include some criteria in the SELECT command as well:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">WHERE</span> email=<span class="hljs-string">'terry@example.edu'</span>;
 <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">-------+-------------------</span>
 Terry | terry@example.edu
(<span class="hljs-number">1</span> <span class="hljs-keyword">row</span>)
</code></pre>
<h3 id="heading-update-rows-in-a-table">UPDATE row(s) in a table</h3>
<p>In order to update one/more piece(s) of information in one/more row(s), we use <code>UPDATE</code> command like what follows:</p>
<pre><code class="lang-pgsql">people-&gt; <span class="hljs-keyword">UPDATE</span> users <span class="hljs-keyword">SET</span> <span class="hljs-type">name</span>=<span class="hljs-string">'Johnny'</span> <span class="hljs-keyword">WHERE</span> email=<span class="hljs-string">'john@example.edu'</span>;
<span class="hljs-keyword">UPDATE</span> <span class="hljs-number">1</span>
</code></pre>
<p><strong>Hint: this command will update any number of rows that meet its criteria.</strong></p>
<p>Lets see how this command changed the last entry of <em>users</em> table:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Peter  | peter@example.edu
 Terry  | terry@example.edu
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
(<span class="hljs-number">4</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h3 id="heading-delete-rows-from-a-table">DELETE row(s) from a table</h3>
<p>To remove one/more row(s) from a table, use the DELETE command like what follows:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">DELETE</span> <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">WHERE</span> email=<span class="hljs-string">'terry@example.edu'</span>;
<span class="hljs-keyword">DELETE</span> <span class="hljs-number">1</span>
</code></pre>
<p><strong>Hint: this command will delete any number of rows that meet its criteria.</strong></p>
<p>Lets see how this command removed an entry of <em>users</em> table:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Peter  | peter@example.edu
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
(<span class="hljs-number">3</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h2 id="heading-sorting">Sorting</h2>
<p>In order to sort list of objects we can use <code>ORDER BY</code> clause in <code>SELECT</code> statements. By default it sort the object by <strong>ascending</strong> order. However, you can explicitly state the order using <code>ASC</code> or <code>DESC</code> to sort the objects in <strong>ascending</strong> or <strong>descending</strong> manner respectively.</p>
<p>In the following example, you can see that at first the objects are not sorted.</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Peter  | peter@example.edu
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
(<span class="hljs-number">3</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<p>Then, when we use <code>ORDER BY</code> clause, it by default sorts the objects in ascending manner. Also, notice that adding the <code>ASC</code> at the end of the command leads to the same result.</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> email;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
 Peter  | peter@example.edu
(<span class="hljs-number">3</span> <span class="hljs-keyword">rows</span>)

people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> email <span class="hljs-keyword">ASC</span>;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
 Peter  | peter@example.edu
(<span class="hljs-number">3</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<p>You can also change the order by stating <code>DESC</code> at the end of the command.</p>
<pre><code class="lang-pgsql">
people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> email <span class="hljs-keyword">DESC</span>;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Peter  | peter@example.edu
 Johnny | john@example.edu
 Eliza  | eliza@example.edu
(<span class="hljs-number">3</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h2 id="heading-wildcardslike-clause">Wildcards/Like clause</h2>
<p>In order to find specific objects we can use <code>LIKE</code> operator in <code>WHERE</code> clauses. For example, to find all the users in whose name have <strong><em>e</em></strong>, we can use the following command:</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">WHERE</span> <span class="hljs-type">name</span> <span class="hljs-keyword">LIKE</span> <span class="hljs-string">'%e%'</span>
;
 <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">-------+-------------------</span>
 Peter | peter@example.edu
 Terry | terry@example.edu
(<span class="hljs-number">2</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<p>Keep in mind that as a result of <code>LIKE</code> operator, the <strong>WHOLE</strong> table will be scanned and the database cannot use indexes to find the records. Therefore, it is a very slow operation.</p>
<h2 id="heading-pagingskipping-objects">Paging/skipping objects</h2>
<p>You can ask the database to limit the number objects in the list by using <code>LIMIT</code> clause. Also you can ask the database to skip a specific number of objects from the beginning of the list by using <code>OFFSET</code> clause.</p>
<p>It is worth mentioning that <code>WHERE</code> and <code>ORDER BY</code> clauses will be executed before <code>LIMIT</code> and <code>OFFSET</code> clauses. In addition note that <code>OFFSET</code> and <code>LIMIT</code> are both very fast and efficient clauses.</p>
<p>Lets see the initial list of the objects in the <em>users</em> table in both orders.</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> email <span class="hljs-keyword">ASC</span>;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Eliza  | eliza@example.edu
 Johnny | john@example.edu
 Peter  | peter@example.edu
 Terry  | terry@example.edu
(<span class="hljs-number">4</span> <span class="hljs-keyword">rows</span>)

people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> email <span class="hljs-keyword">DESC</span>;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Terry  | terry@example.edu
 Peter  | peter@example.edu
 Johnny | john@example.edu
 Eliza  | eliza@example.edu
(<span class="hljs-number">4</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h3 id="heading-limit-clause">LIMIT clause</h3>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> email <span class="hljs-keyword">DESC</span> <span class="hljs-keyword">LIMIT</span> <span class="hljs-number">2</span>;
 <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">-------+-------------------</span>
 Terry | terry@example.edu
 Peter | peter@example.edu
(<span class="hljs-number">2</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h3 id="heading-offset-clause">OFFSET clause</h3>
<p><code>OFFSET</code> starts indexing from 0, therefore index 1 will be the second object in the list.</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> email <span class="hljs-keyword">OFFSET</span> <span class="hljs-number">1</span> <span class="hljs-keyword">LIMIT</span> <span class="hljs-number">2</span>;
  <span class="hljs-type">name</span>  |       email
<span class="hljs-comment">--------+-------------------</span>
 Johnny | john@example.edu
 Peter  | peter@example.edu
(<span class="hljs-number">2</span> <span class="hljs-keyword">rows</span>)
</code></pre>
<h2 id="heading-counting">Counting</h2>
<p>In order to count the number of rows in a result of a query, you can use <code>COUNT</code> clause. <code>COUNT</code> is actually faster than <code>WHERE</code>.</p>
<pre><code class="lang-pgsql">people=&gt; <span class="hljs-keyword">SELECT</span> COUNT(*) <span class="hljs-keyword">FROM</span> users;
 count
<span class="hljs-comment">-------</span>
     <span class="hljs-number">4</span>
(<span class="hljs-number">1</span> <span class="hljs-keyword">row</span>)

people=&gt; <span class="hljs-keyword">SELECT</span> COUNT(*) <span class="hljs-keyword">FROM</span> users <span class="hljs-keyword">WHERE</span> <span class="hljs-type">name</span> <span class="hljs-keyword">LIKE</span> <span class="hljs-string">'%e%'</span>;
 count
<span class="hljs-comment">-------</span>
     <span class="hljs-number">2</span>
(<span class="hljs-number">1</span> <span class="hljs-keyword">row</span>)
</code></pre>
<p>Well, this is the very core of PostgreSQL and I will continue this topic in the further articles.</p>
<p>P.S. The cover is generated by DALL-E.</p>
]]></content:encoded></item><item><title><![CDATA[Simple notes to consider when creating a visualization]]></title><description><![CDATA[Recently I finished a specialization named "Data Visualization with Tableau Specialization" in Coursera, and I believe it was a very comprehensive review of what a person needs to know to start to work with Tableau and also design principles a person...]]></description><link>https://khajeddin.com/simple-notes-to-consider-when-creating-a-visualization</link><guid isPermaLink="true">https://khajeddin.com/simple-notes-to-consider-when-creating-a-visualization</guid><category><![CDATA[data visualization]]></category><category><![CDATA[data analysis]]></category><category><![CDATA[coursera]]></category><category><![CDATA[tableau]]></category><dc:creator><![CDATA[Negar]]></dc:creator><pubDate>Mon, 04 Sep 2023 02:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1693832846226/eba5a388-29e7-4457-b04c-67debbc5b4b1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Recently I finished a specialization named "Data Visualization with Tableau Specialization" in Coursera, and I believe it was a very comprehensive review of what a person needs to know to start to work with Tableau and also design principles a person needs to consider when creating a clear and insightful dashboard with "any" VIZ tool. In what follows, I have summarized the important notes of the first course of this specialization whose name is "Fundamental of Visualization with Tableau". Here are the few steps that anyone who wants to find insights out of a dataset should follow:</p>
<ol>
<li><p><strong>Briefly look at the data and dataset</strong></p>
<p> Take a brief look at your data and try to understand the columns. If you have a document describing the rows and columns, it is in your best interest to read it at least shortly to gain an overview of your dataset.</p>
</li>
<li><p><strong>Identify the potential questions</strong><br /> Try to list several questions regarding the dataset and the context you are working with. Of course, while you are trying to answer these initial questions, you probably face other questions and as you go on the whole context becomes more clear and you will find yourself closer to the most important insights of the dataset. So do not let your possibly short list of questions stop you in this step, push yourself to the next steps and dive into the "data exploration" part.</p>
</li>
<li><p><strong>Create some simple sheets and find simple insights</strong></p>
<p> Try not to be so preoccupied with the style and picky with the correct color of your sheets at this stage. There is a very high chance that you change the color palette as you get more insights from the dataset and reach the end of your viz project. Instead, try to create some rudimentary charts and tables based on your initial questions, understand the relations among the columns and find out the probable need to create other calculated variables to provide better insights.</p>
</li>
</ol>
<p><strong>Make the data pop out</strong></p>
<p>Clean your chart to the point that your audience can get the message; The more we omit the cluttered elements in the chart the more our data pops out. While omitting the unnecessary parts strongly depends on the context that you are working with, applying the following list of actions usually makes sense in more of them:</p>
<ul>
<li><p>Assign clear names to your sheets when you are done with them (Even if you are most likely to delete them later in the process). This simple step makes the whole Exploration process easier.</p>
</li>
<li><p>Remove the unnecessary axes</p>
</li>
<li><p>Remove unnecessary axis titles</p>
</li>
<li><p>Shorten Month names (January --&gt; J, February --&gt; F, etc.)</p>
</li>
<li><p>Remove unnecessary headers</p>
</li>
<li><p>If needed benefit from filter action(s)</p>
</li>
<li><p>Ask others to comment on the readability and understandability of your viz (If your audience gets what you are talking about, you've done good work)</p>
</li>
<li><p>Keep in mind that people from West world read from left to write. Therefore, if it's possible put the most important charts (interaction pattern) in the upper left and the least important ones towards the lower right. We also put</p>
</li>
</ul>
<p> Finally, the course introduces "The top five  Data VIZ best practices" which are:</p>
<ul>
<li><p>Know your audience</p>
</li>
<li><p>Know your data</p>
</li>
<li><p>Use color purposefully</p>
</li>
<li><p>Less is more; Simpler is usually better</p>
</li>
<li><p>Get feedback early and often</p>
</li>
</ul>
<p>Although this course very shortly focuses on the technical part of Tableau, it gives the audience a very great view of what is data visualization as a whole and how to work with the very basic features of Tableau. If a person wants to learn more about the Basic Features of Tableau in a short amount of time, I recommend them to follow the first course of this specialization and then skip to the third course and follow that one as well.</p>
<p>I will continue summarizing the course contents of this specialization.</p>
<p> Best of luck.</p>
<p>Cover credit: BING search engine</p>
]]></content:encoded></item><item><title><![CDATA[SQL (Structured Query Language) Basic Commands]]></title><description><![CDATA[In order to use SQL-based databases, one needs to become familiar with SQL clauses, keywords and queries. In this post we are going through some of the most basic SQL clauses and keywords using simple examples.
SQL Comments:
You can write comments in...]]></description><link>https://khajeddin.com/sql-structured-query-language-basic-commands</link><guid isPermaLink="true">https://khajeddin.com/sql-structured-query-language-basic-commands</guid><category><![CDATA[SQL]]></category><category><![CDATA[Databases]]></category><category><![CDATA[SQLite]]></category><category><![CDATA[#SQLtutorial ]]></category><category><![CDATA[MSSQL]]></category><category><![CDATA[commands in sql]]></category><dc:creator><![CDATA[Negar]]></dc:creator><pubDate>Sun, 11 Jun 2023 14:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1706004087677/edb58685-ae9b-43b5-bdb2-1eec2b9a11ba.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In order to use SQL-based databases, one needs to become familiar with SQL clauses, keywords and queries. In this post we are going through some of the most basic SQL clauses and keywords using simple examples.</p>
<h2 id="heading-sql-comments">SQL Comments:</h2>
<p>You can write comments in SQL files in two ways:</p>
<p>1. Single-Line comment:</p>
<p>You can create a single-line comment using two dashes:</p>
<p><img alt /></p>
<p>2. Block comment:</p>
<p>You can create a block comment starting with /* and ending with */. This is especially helpful when you want to create a comment which has more than one line. for example, it is a good practice to write a block comment at the beginning of your SQL file and specify the file's creator, date of creation and description.</p>
<p><img alt /></p>
<h2 id="heading-select">SELECT:</h2>
<p>Use SELECT clause to columns you want to appear in the result table.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696250586651/89652902-9fb6-448b-992f-3ae5e897d05e.png" alt /></p>
<h2 id="heading-alias">Alias:</h2>
<p>To make your results more readable for yourself and others you can change the way columns' names are displayed in the result. For this purpose, you should use AS keyword, as shown in the following example:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696250671380/6b6c7471-66c2-4e3e-ad5e-25be2cea076b.png" alt /></p>
<p>As can be seen in the above example, for using an alias including more than one word we should put that multi-word alias between [ ] or ' '. However, we can bring a single-word alias immediately after AS without using any other special characters.</p>
<h2 id="heading-sorting-with-order-by">Sorting with ORDER BY:</h2>
<p>We can sort results of our queries based on column contents. In order to do that, we use ORDER BY clause after FROM clause. Hint the following example which sorts the result table based on the contents of the LastName column.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696250933902/d37ae2cb-76e7-4828-a3ce-e3401adf457f.png" alt /></p>
<p>The default mode of ORDER BY clause is <strong>ascending</strong> order. However, you can change it. You can use <strong>ASC</strong> for ascending or <strong>DESC</strong> for descending order. Use either of these two keywords after the column name stated in the ORDER BY clause. For example, to sort the result table based on LasrName descending order we should use the following query:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696251068374/65a33f18-95b1-451e-819a-d5bd20622e8d.png" alt /></p>
<p>We can sort the results based on multiple columns. For example:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696251220771/476a0fcc-0d7e-4bab-9a2a-0d85c285bca0.png" alt /></p>
<h2 id="heading-limit">LIMIT:</h2>
<p>You can limit the number of records shown in the result table using LIMIT Clause. In order to do that, you have to use "LIMIT number-of-rows" in your query. For example:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1696251358073/46583ef1-51fe-48a7-8b87-dc4e8f1ab492.png" alt /></p>
<p>In the above example, number of rows in the result tables is limited to 10. Therefore, the result table will contain the information of the top 10 customers sorted with the specified order in the query.</p>
<p>P.S. The cover image is generated by DALL-E.</p>
]]></content:encoded></item></channel></rss>