<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mysql Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/mysql/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Thu, 11 Dec 2025 13:13:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>SQL-Basics: Relations</title>
		<link>https://creatronix.de/sql-basics-relations/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Thu, 18 Apr 2019 08:02:28 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[constraint]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1326</guid>

					<description><![CDATA[<p>As the Junior Data Scientist of Knight Industries we created a table to keep track of all our operatives: SQL-Basics: Create, Read, Update, Delete Devon asks us to keep track of our operations aka missions as well. For the first implementation let us assume that a mission has one operative and an operative can participate&#8230;</p>
<p>The post <a href="https://creatronix.de/sql-basics-relations/">SQL-Basics: Relations</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As the Junior Data Scientist of Knight Industries we created a table to keep track of all our operatives: <a href="https://creatronix.de/sql-basics-create-read-update-delete/">SQL-Basics: Create, Read, Update, Delete</a></p>
<p>Devon asks us to keep track of our operations aka missions as well. For the first implementation let us assume that a mission has one operative and an operative can participate in multiple missions. that&#8217;s what we call an 1 to many relationship.</p>
<pre>  +------------+                 +----------+
  |            |1   active in   n|          |
  | operative  +-----------------+ missions |
  |            |                 |          |
  +------------+                 +----------+
</pre>
<p>Missions have an id, a code name like &#8220;Phantom Liberty&#8221;, an operative id and a total cost.</p>
<p>To say that the operative id is equivalent to the id in the operative column we use the FOREIGN KEY constraint.</p>
<p>So let&#8217;s create the new table in our database:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-sql" data-lang="SQL"><code>CREATE TABLE ki_missions 
(id INTEGER, code_name TEXT, operative_id INTEGER, total_cost DECIMAL(15,2), PRIMARY KEY(id), FOREIGN KEY (operative_id) REFERENCES operatives(id));
INSERT INTO ki_missions VALUES (1, "Knight of the Phoenix", 1, 6246382.43);
INSERT INTO ki_missions VALUES (2, "Deadly Maneuvers", 1, 4568893.53);</code></pre>
</div>
<p>Our first join</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-sql" data-lang="SQL"><code>SELECT ki_missions.code_name, ki_operatives.name FROM ki_missions LEFT JOIN ki_operatives ON ki_missions.operative_id = ki_operatives.id;</code></pre>
</div>
<p>More on joins <a href="https://dsin.files.wordpress.com/2013/03/sqljoins_cheatsheet.png">https://dsin.files.wordpress.com/2013/03/sqljoins_cheatsheet.png</a></p>
<p>Next chapter: <a href="https://creatronix.de/sql-functions/">SQL-Functions &#8211; SQL-Basics 3</a></p>
<p>&nbsp;</p>
<p>The post <a href="https://creatronix.de/sql-basics-relations/">SQL-Basics: Relations</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL &#8211; the dark side</title>
		<link>https://creatronix.de/sql-the-dark-side/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Thu, 08 Feb 2018 13:47:46 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[disable]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[safe update]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1287</guid>

					<description><![CDATA[<p>Sometimes your RDBMS does not allow you to do certain changes like updating a table without using a WHERE clause that uses a key column. When you are really sure what you want to do: SET SQL_SAFE_UPDATES = 0; Now the dirty brown magic can begin! Back to the SQL-Tutorial</p>
<p>The post <a href="https://creatronix.de/sql-the-dark-side/">SQL &#8211; the dark side</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Sometimes your RDBMS does not allow you to do certain changes like updating a table without using a WHERE clause that uses a key column.</p>
<p>When you are really sure what you want to do:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-sql" data-lang="SQL"><code>SET SQL_SAFE_UPDATES = 0;</code></pre>
</div>
<p>Now the dirty brown magic can begin!</p>
<p>Back to the <a href="https://creatronix.de/sql-tutorial/">SQL-Tutorial</a></p>
<p>The post <a href="https://creatronix.de/sql-the-dark-side/">SQL &#8211; the dark side</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL-Basics &#8211; Subqueries: Update column with values from another column</title>
		<link>https://creatronix.de/sql-subqueries-update-column-with-values-from-another-column/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Wed, 07 Feb 2018 15:38:42 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[normalization]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[subqueries]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1278</guid>

					<description><![CDATA[<p>Sometimes You screw up your database design and you have redundancies i.e. your database is not normalized. If You want to correct that: Subqueries for the rescue! In our example we have two tables which contain almost the same information: CREATE TABLE installed_device (`id` int, `device` text, `info` text); INSERT INTO installed_device (`id`, `device`, `info`)&#8230;</p>
<p>The post <a href="https://creatronix.de/sql-subqueries-update-column-with-values-from-another-column/">SQL-Basics &#8211; Subqueries: Update column with values from another column</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Sometimes You screw up your database design and you have redundancies i.e. your database is not normalized. If You want to correct that: Subqueries for the rescue!</p>
<p>In our example we have two tables which contain almost the same information:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-sql" data-lang="SQL"><code>CREATE TABLE installed_device (`id` int, `device` text, `info` text);
INSERT INTO installed_device (`id`, `device`, `info`) VALUES (1, "Device_1", "Works!"), (2, "Device_2", "Doesn't work!");
CREATE TABLE device (`id` int, `device_name` text);
INSERT INTO device (`id`, `device_name`) VALUES  (1, "Device_1"), (2, "Device_2");</code></pre>
</div>
<p>&nbsp;</p>
<p>installed_device</p>
<table>
<tbody>
<tr>
<th>id</th>
<th>device</th>
<th>info</th>
</tr>
<tr>
<td>1</td>
<td>Device_1</td>
<td>Works!</td>
</tr>
<tr>
<td>2</td>
<td>Device_2</td>
<td>Doesn&#8217;t work!</td>
</tr>
</tbody>
</table>
<p>device</p>
<table>
<tbody>
<tr>
<th>id</th>
<th>device_name</th>
</tr>
<tr>
<td>1</td>
<td>Device_1</td>
</tr>
<tr>
<td>2</td>
<td>Device_2</td>
</tr>
</tbody>
</table>
<p>The goal is to replace the values in installed_device&#8217;s device column with the id from table device:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-sql" data-lang="SQL"><code>UPDATE installed_device SET device = (SELECT id FROM device WHERE device.device_name = installed_device.device);</code></pre>
</div>
<p>The Result</p>
<table>
<tbody>
<tr>
<th>id</th>
<th>device</th>
<th>info</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>Works!</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>Doesn&#8217;t work!</td>
</tr>
</tbody>
</table>
<p>The post <a href="https://creatronix.de/sql-subqueries-update-column-with-values-from-another-column/">SQL-Basics &#8211; Subqueries: Update column with values from another column</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
