<?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>subqueries Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/subqueries/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/subqueries/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Thu, 11 Dec 2025 07:11:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<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>
