<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wikitechia.top/index.php?action=history&amp;feed=atom&amp;title=SQL_-_Data_Modeling</id>
	<title>SQL - Data Modeling - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wikitechia.top/index.php?action=history&amp;feed=atom&amp;title=SQL_-_Data_Modeling"/>
	<link rel="alternate" type="text/html" href="http://wikitechia.top/index.php?title=SQL_-_Data_Modeling&amp;action=history"/>
	<updated>2026-10-26T03:17:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>http://wikitechia.top/index.php?title=SQL_-_Data_Modeling&amp;diff=1927&amp;oldid=prev</id>
		<title>Root: Root moved page SQL DML to SQL - Data Modeling without leaving a redirect</title>
		<link rel="alternate" type="text/html" href="http://wikitechia.top/index.php?title=SQL_-_Data_Modeling&amp;diff=1927&amp;oldid=prev"/>
		<updated>2026-01-14T13:32:11Z</updated>

		<summary type="html">&lt;p&gt;Root moved page &lt;a href=&quot;/index.php?title=SQL_DML&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;SQL DML (page does not exist)&quot;&gt;SQL DML&lt;/a&gt; to &lt;a href=&quot;/index.php/SQL_-_Data_Modeling&quot; title=&quot;SQL - Data Modeling&quot;&gt;SQL - Data Modeling&lt;/a&gt; without leaving a redirect&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 14:32, 14 January 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Root</name></author>
	</entry>
	<entry>
		<id>http://wikitechia.top/index.php?title=SQL_-_Data_Modeling&amp;diff=1926&amp;oldid=prev</id>
		<title>Root: Created page with &quot;= Introduction =  &#039;&#039;&#039;SQL&#039;&#039;&#039; (Structured Query Language): is a standard language for communication with relational databases. That is, a standardized language that allows working with the majority of relational databases. &#039;&#039;&#039;SQL&#039;&#039;&#039; can be used within other programming languages. The main characteristic of this language is its simplicity, as with little knowledge basic queries can be performed on a database, although it does not cease to be a complete language, both relati...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wikitechia.top/index.php?title=SQL_-_Data_Modeling&amp;diff=1926&amp;oldid=prev"/>
		<updated>2026-01-14T13:16:29Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Introduction =  &amp;#039;&amp;#039;&amp;#039;SQL&amp;#039;&amp;#039;&amp;#039; (Structured Query Language): is a standard language for communication with relational databases. That is, a standardized language that allows working with the majority of relational databases. &amp;#039;&amp;#039;&amp;#039;SQL&amp;#039;&amp;#039;&amp;#039; can be used within other programming languages. The main characteristic of this language is its simplicity, as with little knowledge basic queries can be performed on a database, although it does not cease to be a complete language, both relati...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SQL&amp;#039;&amp;#039;&amp;#039; (Structured Query Language): is a standard language for communication with relational databases. That is, a standardized language that allows working with the majority of relational databases. &amp;#039;&amp;#039;&amp;#039;SQL&amp;#039;&amp;#039;&amp;#039; can be used within other programming languages. The main characteristic of this language is its simplicity, as with little knowledge basic queries can be performed on a database, although it does not cease to be a complete language, both relationally and computationally.&lt;br /&gt;
&lt;br /&gt;
The SQL language can be divided into three sets of instructions or statements according to their function:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DDL&amp;#039;&amp;#039;&amp;#039;-Data Definition Language: Definition statements, which allow creating, modifying, and deleting data structures.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DML&amp;#039;&amp;#039;&amp;#039;-Data Manipulation Language: Manipulation statements, which allow reading, inserting, modifying, and deleting records.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DCL&amp;#039;&amp;#039;&amp;#039;-Data Control Language: Control statements, which allow finalizing or rejecting transactions and authorizing or revoking user permissions.&lt;br /&gt;
&lt;br /&gt;
Structured Query Language (&amp;#039;&amp;#039;&amp;#039;SQL&amp;#039;&amp;#039;&amp;#039;) is a language for databases designed to manage data stored in a relational database management system. The first version of SQL was initially developed by IBM in the early 70s. In 86 it became an ANSI standard and in 87 an ISO standard. The initial version, called &amp;#039;&amp;#039;&amp;#039;SEQUEL&amp;#039;&amp;#039;&amp;#039; (Structured English Query Language), was designed to manipulate and extract data stored in IBM&amp;#039;s quasi-relational database management system *System R*. Then, at the end of the 70s, the company *Relational Software Inc.*, which is now *Oracle Corporation*, introduced the first commercially available implementation of SQL: *Oracle V2* for VAX computers.&lt;br /&gt;
&lt;br /&gt;
Many of the DBMS available today, such as Oracle Database, Microsoft SQL Server, MySQL, MariaDB, or PostgreSQL, use SQL.&lt;br /&gt;
&lt;br /&gt;
Despite the standardization of SQL, each manufacturer uses various extensions and variants that make some adaptations necessary to move SQL code from one system to another.&lt;br /&gt;
&lt;br /&gt;
In a DBMS, SQL is used to:&lt;br /&gt;
&lt;br /&gt;
* Create the database and the tables: DDL&lt;br /&gt;
* Perform basic data management operations (addition, deletion, and modification): DML&lt;br /&gt;
* Perform simple or complex queries to select and order the stored data and transform them into useful information: DML&lt;br /&gt;
&lt;br /&gt;
The data manipulation language of SQL (Data Manipulation Language, DML) is used to query and modify the database data. In this section, we will describe how the DML statements SELECT, INSERT, UPDATE, and DELETE are used, which are defined below:&lt;br /&gt;
&lt;br /&gt;
* SELECT - to query data from the database&lt;br /&gt;
* INSERT - to insert data into a table&lt;br /&gt;
* UPDATE - to update data in a table&lt;br /&gt;
* DELETE - to delete data from a table&lt;br /&gt;
&lt;br /&gt;
In a DML SQL statement:&lt;br /&gt;
&lt;br /&gt;
* Each clause in a statement should start on a new line&lt;br /&gt;
* The beginning of each clause should align with the beginning of the other clauses&lt;br /&gt;
* If a clause has several parts, they should appear on separate lines and be indented under the beginning of the clause to show the relationship&lt;br /&gt;
* Uppercase letters are used to represent reserved words&lt;br /&gt;
* Lowercase letters are used to represent user-defined words&lt;br /&gt;
&lt;br /&gt;
== Installation of software for the follow-up of the UF ==&lt;br /&gt;
&lt;br /&gt;
Note: In this course, the DBMS MariaDB will be used with the WorkBench application to work with it.&lt;br /&gt;
&lt;br /&gt;
=== Installation of the DBMS ===&lt;br /&gt;
&lt;br /&gt;
Installation of the DBMS&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;MariaDB&amp;#039;&amp;#039;&amp;#039;: is a branch of the MySQL database management system driven by the community, in order to maintain its free status under the GNU GPL, due to the uncertainty of the status of the MySQL license now that it is under the ownership of Oracle. Likewise, there is the intention to maintain high fidelity with MySQL, which guarantees a &amp;quot;drop-in&amp;quot; substitution capability due to the equivalence of the binary library and compatibility with the APIs and MySQL commands.&lt;br /&gt;
&lt;br /&gt;
Documentation and download: [web link](https://mariadb.com/get-started-with-mariadb/)&lt;br /&gt;
&lt;br /&gt;
==== Accessing and exiting MariaDB/MySQL ====&lt;br /&gt;
&lt;br /&gt;
To access the DBMS: From the command line:&lt;br /&gt;
&lt;br /&gt;
MariaDB access command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mariadb –u root –p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MySQL access command:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mysql –u root –p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The parameter -u indicates the user, and -p indicates that it will request the password (you must have the path in the PATH, otherwise search for the BIN directory of MYSQL).&lt;br /&gt;
&lt;br /&gt;
Note: If you have not modified it, the root password is empty.&lt;br /&gt;
&lt;br /&gt;
If you manage to enter, it will appear as a prompt:&lt;br /&gt;
&lt;br /&gt;
MariaDB DBMS prompt:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
MariaDB&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MySQL DBMS prompt:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
MySQL&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access to a database ===&lt;br /&gt;
&lt;br /&gt;
If we know the database we want to work with, we will do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mysql database_name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If instead we enter only with the mysql command, we will then have to execute the USE command to indicate which database we want to work with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
MariaDB&amp;gt; USE database_name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To exit we do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
MariaDB&amp;gt; quit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Installation of the work tool ===&lt;br /&gt;
&lt;br /&gt;
The recommended work tool is the DBeaver application, which is a universal and free database tool ([link](https://dbeaver.io/)).&lt;br /&gt;
&lt;br /&gt;
==== Installation and use of the DBeaver application ====&lt;br /&gt;
&lt;br /&gt;
Steps for installation:&lt;br /&gt;
&lt;br /&gt;
1. Download and install DBeaver: [download link](https://dbeaver.io/download/)&lt;br /&gt;
2. Configure a connection:&lt;br /&gt;
&lt;br /&gt;
{IMAGE_PLACEMENT}&lt;br /&gt;
&lt;br /&gt;
=== Starting/Stopping the MySQL service ===&lt;br /&gt;
&lt;br /&gt;
=== Possible problems accessing MariaDB ===&lt;br /&gt;
&lt;br /&gt;
== Commands in MySQL/MariaDB and brief introduction to DDL (Data Definition Language) ==&lt;br /&gt;
&lt;br /&gt;
=== Comments in SQL ===&lt;br /&gt;
&lt;br /&gt;
Comments can be made on a single line by starting the line with the character &amp;quot;#&amp;quot; or &amp;quot;--&amp;quot; (two hyphens followed by a space).&lt;br /&gt;
&lt;br /&gt;
Multi-line comments can also be made by starting with &amp;quot;/*&amp;quot; and ending with &amp;quot;*/&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Example 1. SQL Comments&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# This is a comment&lt;br /&gt;
-- This is also a comment&lt;br /&gt;
/* This is a multi-line&lt;br /&gt;
comment */&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating databases and adding records with SQL in the MySQL/MariaDB environment ===&lt;br /&gt;
&lt;br /&gt;
=== Creating and deleting a database ===&lt;br /&gt;
&lt;br /&gt;
The CREATE DATABASE statement creates a new database.&lt;br /&gt;
&lt;br /&gt;
Example 2. Creating a database&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
CREATE DATABASE database_name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DROP DATABASE statement deletes an existing database and all its tables.&lt;br /&gt;
&lt;br /&gt;
Example 3. Deleting a database&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
DROP DATABASE database_name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating tables ===&lt;br /&gt;
&lt;br /&gt;
The CREATE TABLE statement is used to create a new table.&lt;br /&gt;
&lt;br /&gt;
Syntax of the CREATE TABLE statement:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
CREATE TABLE table_name (&lt;br /&gt;
  column1 data_type [column_options],&lt;br /&gt;
  column2 data_type [column_options],&lt;br /&gt;
  ...&lt;br /&gt;
  [table_options]&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Data types ===&lt;br /&gt;
&lt;br /&gt;
To define a table, we must specify the name of each column and its data type.&lt;br /&gt;
&lt;br /&gt;
Common numeric types:&lt;br /&gt;
* TINYINT: Very small integer.&lt;br /&gt;
* INT: Normal size integer.&lt;br /&gt;
* FLOAT: Small decimal point number.&lt;br /&gt;
* DOUBLE: Large decimal point number.&lt;br /&gt;
* DECIMAL(p,s): Fixed point number.&lt;br /&gt;
&lt;br /&gt;
Common string types:&lt;br /&gt;
* CHAR(n): Fixed length string.&lt;br /&gt;
* VARCHAR(n): Variable length string.&lt;br /&gt;
* TEXT: Large text blocks.&lt;br /&gt;
&lt;br /&gt;
Common date types:&lt;br /&gt;
* DATE: Date (YYYY-MM-DD).&lt;br /&gt;
* TIME: Time (HH:MM:SS).&lt;br /&gt;
* DATETIME: Date and time.&lt;br /&gt;
&lt;br /&gt;
=== Column options ===&lt;br /&gt;
&lt;br /&gt;
Columns can have various modifiers:&lt;br /&gt;
* NOT NULL: The column cannot contain NULL values.&lt;br /&gt;
* UNIQUE: All values in the column must be different.&lt;br /&gt;
* PRIMARY KEY: Identifies the column as the primary key.&lt;br /&gt;
* AUTO_INCREMENT: The system automatically generates a unique number for each new record.&lt;br /&gt;
* DEFAULT value: Assigns a value if none is provided.&lt;br /&gt;
&lt;br /&gt;
=== Table options ===&lt;br /&gt;
&lt;br /&gt;
* ENGINE: Storage engine (e.g., InnoDB).&lt;br /&gt;
* DEFAULT CHARSET: Character set.&lt;br /&gt;
* COLLATE: Sorting rules.&lt;br /&gt;
&lt;br /&gt;
= Querying data: SELECT statement =&lt;br /&gt;
&lt;br /&gt;
== SELECT ==&lt;br /&gt;
&lt;br /&gt;
The SELECT statement is used to select data from a database.&lt;br /&gt;
&lt;br /&gt;
Example 4. Basic SELECT&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM table_name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To select specific columns:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT column1, column2 FROM table_name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ORDER BY ==&lt;br /&gt;
&lt;br /&gt;
The ORDER BY keyword is used to sort the result-set in ascending or descending order.&lt;br /&gt;
&lt;br /&gt;
Example 5. Sorting&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Employees ORDER BY LastName ASC;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SELECT DISTINCT ==&lt;br /&gt;
&lt;br /&gt;
The SELECT DISTINCT statement is used to return only distinct (different) values.&lt;br /&gt;
&lt;br /&gt;
Example 6. Distinct values&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT DISTINCT City FROM Customers;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Aliases ==&lt;br /&gt;
&lt;br /&gt;
SQL aliases are used to give a table, or a column in a table, a temporary name.&lt;br /&gt;
&lt;br /&gt;
Example 7. Column Alias&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT FirstName AS Name FROM Employees;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SELECT statement with WHERE criteria ==&lt;br /&gt;
&lt;br /&gt;
The WHERE clause is used to filter records.&lt;br /&gt;
&lt;br /&gt;
=== Comparison operators for text strings ===&lt;br /&gt;
&lt;br /&gt;
* = : Equal&lt;br /&gt;
* != or &amp;lt;&amp;gt; : Not equal&lt;br /&gt;
&lt;br /&gt;
=== Comparison operators for numbers and dates ===&lt;br /&gt;
&lt;br /&gt;
* = : Equal&lt;br /&gt;
* &amp;lt; : Less than&lt;br /&gt;
* &amp;gt; : Greater than&lt;br /&gt;
* &amp;lt;= : Less than or equal&lt;br /&gt;
* &amp;gt;= : Greater than or equal&lt;br /&gt;
&lt;br /&gt;
=== Specifying ranges with BETWEEN ===&lt;br /&gt;
&lt;br /&gt;
Example 8. Using BETWEEN&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Joining criteria with AND and OR ===&lt;br /&gt;
&lt;br /&gt;
Example 9. Logic operators&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Customers WHERE City=&amp;#039;Madrid&amp;#039; AND PostalCode &amp;gt; 28000;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Combining multiple AND and OR ===&lt;br /&gt;
&lt;br /&gt;
Use parentheses to group conditions.&lt;br /&gt;
&lt;br /&gt;
Example 10. Combined logic&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Employees WHERE (Job=&amp;#039;Manager&amp;#039; AND Salary &amp;gt; 3000) OR Job=&amp;#039;Director&amp;#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== IN operator ===&lt;br /&gt;
&lt;br /&gt;
Allows you to specify multiple values in a WHERE clause.&lt;br /&gt;
&lt;br /&gt;
Example 11. Using IN&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Customers WHERE Country IN (&amp;#039;Germany&amp;#039;, &amp;#039;France&amp;#039;, &amp;#039;UK&amp;#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The NULL value ===&lt;br /&gt;
&lt;br /&gt;
IS NULL and IS NOT NULL are used to check for empty values.&lt;br /&gt;
&lt;br /&gt;
Example 12. Checking NULLs&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Books WHERE Price IS NULL;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Use of wildcards in the LIKE clause ==&lt;br /&gt;
&lt;br /&gt;
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.&lt;br /&gt;
&lt;br /&gt;
* % - Represents zero, one, or multiple characters.&lt;br /&gt;
* _ - Represents a single character.&lt;br /&gt;
&lt;br /&gt;
Example 13. Wildcards&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Customers WHERE Name LIKE &amp;#039;a%&amp;#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing strings with LIKE and with = ===&lt;br /&gt;
&lt;br /&gt;
By default, string comparisons are case-insensitive. Use BINARY for case-sensitive matches.&lt;br /&gt;
&lt;br /&gt;
Example 14. Binary comparison&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT BINARY &amp;#039;à&amp;#039; = &amp;#039;a&amp;#039;; -- Returns 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SELECT statement with LIMIT clause ==&lt;br /&gt;
&lt;br /&gt;
LIMIT is used to specify the number of records to return.&lt;br /&gt;
&lt;br /&gt;
Example 15. Simple limit&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Employees LIMIT 5;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example 16. Limit with offset (skip 4, take 1)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM Books ORDER BY Price DESC LIMIT 4, 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SELECT statement with GROUP BY clause ==&lt;br /&gt;
&lt;br /&gt;
The GROUP BY statement groups rows that have the same values into summary rows.&lt;br /&gt;
&lt;br /&gt;
=== Use of COUNT with GROUP BY ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT COUNT(*), Salary FROM Employees GROUP BY Salary;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Use of AVG and SUM with GROUP BY ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT AVG(Salary) FROM Employees GROUP BY Department;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Use of GROUP BY for more than one column ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT Department, Job, SUM(Salary) FROM Employees GROUP BY Department, Job;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction on the use of GROUP BY ===&lt;br /&gt;
&lt;br /&gt;
Columns in the SELECT clause must either be in the GROUP BY clause or used in an aggregate function.&lt;br /&gt;
&lt;br /&gt;
== Restricting rows with HAVING ==&lt;br /&gt;
&lt;br /&gt;
The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.&lt;br /&gt;
&lt;br /&gt;
Example 17. Using HAVING&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT COUNT(*) AS Num, Salary &lt;br /&gt;
FROM Employees &lt;br /&gt;
GROUP BY Salary &lt;br /&gt;
HAVING Num &amp;gt; 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Chapter 3. Built-in functions =&lt;br /&gt;
&lt;br /&gt;
== Aggregation functions ==&lt;br /&gt;
&lt;br /&gt;
* COUNT(): Number of rows.&lt;br /&gt;
* SUM(): Total sum.&lt;br /&gt;
* AVG(): Average value.&lt;br /&gt;
* MIN(): Smallest value.&lt;br /&gt;
* MAX(): Largest value.&lt;br /&gt;
&lt;br /&gt;
== Time and date functions ==&lt;br /&gt;
&lt;br /&gt;
=== Obtaining parts of a date ===&lt;br /&gt;
&lt;br /&gt;
* YEAR(), MONTH(), DAY(), HOUR(), MINUTE(), SECOND().&lt;br /&gt;
&lt;br /&gt;
=== Obtaining the current time ===&lt;br /&gt;
&lt;br /&gt;
* NOW(), CURDATE(), CURTIME().&lt;br /&gt;
&lt;br /&gt;
=== Calculation of dates ===&lt;br /&gt;
&lt;br /&gt;
* ADDDATE(), DATE_ADD(), SUBDATE(), DATE_SUB(), DATEDIFF().&lt;br /&gt;
&lt;br /&gt;
=== Date format ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT DATE_FORMAT(NOW(), &amp;quot;%d-%m-%Y&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mathematical functions ==&lt;br /&gt;
&lt;br /&gt;
* ROUND(): Rounding.&lt;br /&gt;
* FLOOR(): Round down.&lt;br /&gt;
* POW(): Power.&lt;br /&gt;
* SQRT(): Square root.&lt;br /&gt;
&lt;br /&gt;
== Hash and password functions ==&lt;br /&gt;
&lt;br /&gt;
* MD5(): MD5 hash.&lt;br /&gt;
* SHA1(): SHA1 hash.&lt;br /&gt;
&lt;br /&gt;
== String functions ==&lt;br /&gt;
&lt;br /&gt;
* CONCAT(): Joins strings.&lt;br /&gt;
* CHAR_LENGTH(): String length.&lt;br /&gt;
* UPPER() / LOWER(): Case conversion.&lt;br /&gt;
* LEFT() / RIGHT(): Extracts characters.&lt;br /&gt;
&lt;br /&gt;
== Execution control functions ==&lt;br /&gt;
&lt;br /&gt;
* IFNULL(val, default): Returns default if val is NULL.&lt;br /&gt;
* COALESCE(list): Returns the first non-NULL value.&lt;br /&gt;
&lt;br /&gt;
= Order of execution in a SELECT query =&lt;br /&gt;
&lt;br /&gt;
The order of execution in an SQL query does not always follow the order in which the clauses appear in the written query. The typical execution order of an SQL query is as follows:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;FROM&amp;#039;&amp;#039;&amp;#039;: Specifies the tables from which the data is read.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;WHERE&amp;#039;&amp;#039;&amp;#039;: Filters the rows of the tables according to the specified condition.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;GROUP BY&amp;#039;&amp;#039;&amp;#039;: Groups the rows that meet the WHERE condition into categories based on one or more columns.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;HAVING&amp;#039;&amp;#039;&amp;#039;: Filters the categories generated by the GROUP BY according to the specified condition.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;SELECT&amp;#039;&amp;#039;&amp;#039;: Specifies the columns to be displayed in the query result; it can include aggregation functions such as MAX, SUM, etc.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;ORDER BY&amp;#039;&amp;#039;&amp;#039;: Sorts the result of the query based on one or more columns.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;LIMIT&amp;#039;&amp;#039;&amp;#039;: Limits the number of rows displayed in the result and, optionally, specifies the starting point from which they should be shown.&lt;br /&gt;
&lt;br /&gt;
The order of execution is important because, for example, if we do not use a &amp;#039;&amp;#039;&amp;#039;GROUP BY&amp;#039;&amp;#039;&amp;#039; after using an aggregation function, we will not be able to use &amp;#039;&amp;#039;&amp;#039;HAVING&amp;#039;&amp;#039;&amp;#039;, as it only acts upon the categories generated by the group.&lt;br /&gt;
&lt;br /&gt;
In summary, in the &amp;#039;&amp;#039;&amp;#039;HAVING&amp;#039;&amp;#039;&amp;#039; clause, you can use the aliases created via aggregation functions (such as COUNT, MAX, etc.) in the &amp;#039;&amp;#039;&amp;#039;SELECT&amp;#039;&amp;#039;&amp;#039; clause for the filtering conditions that affect the categories generated by the &amp;#039;&amp;#039;&amp;#039;GROUP BY&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
= Subqueries =&lt;br /&gt;
&lt;br /&gt;
A subquery is a query within another query.&lt;br /&gt;
&lt;br /&gt;
== Subqueries with comparison operators ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT Name FROM Products WHERE Price &amp;gt; (SELECT AVG(Price) FROM Products);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subqueries and the IN operator ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT Name FROM Customers WHERE id IN (SELECT CustomerID FROM Orders);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== IN and LIMIT operators ===&lt;br /&gt;
&lt;br /&gt;
== The ANY and ALL modifiers ==&lt;br /&gt;
&lt;br /&gt;
Used to compare a value to any or all values in a set.&lt;br /&gt;
&lt;br /&gt;
== Subqueries with EXISTS and NOT EXISTS ==&lt;br /&gt;
&lt;br /&gt;
Tests for the existence of any record in a subquery.&lt;br /&gt;
&lt;br /&gt;
== Subqueries in the SELECT clause ==&lt;br /&gt;
&lt;br /&gt;
= Chapter 6. Joining tables - JOIN =&lt;br /&gt;
&lt;br /&gt;
== INNER JOIN ==&lt;br /&gt;
&lt;br /&gt;
Returns records that have matching values in both tables.&lt;br /&gt;
&lt;br /&gt;
== OUTER JOIN ==&lt;br /&gt;
&lt;br /&gt;
=== LEFT OUTER JOIN ===&lt;br /&gt;
&lt;br /&gt;
Returns all records from the left table, and matched records from the right.&lt;br /&gt;
&lt;br /&gt;
=== RIGHT OUTER JOIN ===&lt;br /&gt;
&lt;br /&gt;
Returns all records from the right table, and matched records from the left.&lt;br /&gt;
&lt;br /&gt;
=== FULL OUTER JOIN ===&lt;br /&gt;
&lt;br /&gt;
Returns all records when there is a match in either left or right table.&lt;br /&gt;
&lt;br /&gt;
== CROSS JOIN ==&lt;br /&gt;
&lt;br /&gt;
Returns the Cartesian product of the two tables.&lt;br /&gt;
&lt;br /&gt;
=== Examples of JOIN queries ===&lt;br /&gt;
&lt;br /&gt;
==== JOIN ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT first_name, last_name &lt;br /&gt;
FROM customers c &lt;br /&gt;
JOIN orders o ON o.customer_id = c.id;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Multiple JOIN ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT o.order_date, p.product_name &lt;br /&gt;
FROM products p &lt;br /&gt;
JOIN order_details od ON od.product_id = p.id &lt;br /&gt;
JOIN orders o ON od.order_id = o.id;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LEFT JOIN ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT c.Name, o.OrderID &lt;br /&gt;
FROM Customers c &lt;br /&gt;
LEFT JOIN Orders o ON c.CustomerID = o.CustomerID;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FROM of more than one table ==&lt;br /&gt;
&lt;br /&gt;
Comma-separated tables in FROM clause act as a CROSS JOIN.&lt;br /&gt;
&lt;br /&gt;
= Modification of data: INSERT, UPDATE and DELETE statements =&lt;br /&gt;
&lt;br /&gt;
== INSERT statement ==&lt;br /&gt;
&lt;br /&gt;
Used to insert new records in a table.&lt;br /&gt;
&lt;br /&gt;
Syntax:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
INSERT INTO table_name (col1, col2) VALUES (val1, val2);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inserting rows with a SELECT statement ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
INSERT INTO Table2 SELECT * FROM Table1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== INSERT with auto-generated keys ===&lt;br /&gt;
&lt;br /&gt;
Use LAST_INSERT_ID() to retrieve the ID of the last inserted row.&lt;br /&gt;
&lt;br /&gt;
=== INSERT without auto-generated keys ===&lt;br /&gt;
&lt;br /&gt;
Calculate the ID manually using variables.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT MAX(Id)+1 INTO @next_id FROM MyTable;&lt;br /&gt;
INSERT INTO MyTable (Id, Name) VALUES (@next_id, &amp;#039;Example&amp;#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UPDATE statement ==&lt;br /&gt;
&lt;br /&gt;
Used to modify existing records.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
UPDATE table_name &lt;br /&gt;
SET column1 = value1 &lt;br /&gt;
WHERE condition;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inclusion of subqueries in an UPDATE statement ===&lt;br /&gt;
&lt;br /&gt;
== DELETE statement ==&lt;br /&gt;
&lt;br /&gt;
Used to delete records.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
DELETE FROM table_name WHERE condition;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:IT Databases]]&lt;/div&gt;</summary>
		<author><name>Root</name></author>
	</entry>
</feed>