<?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>Marko Bischof &#187; MySQL</title>
	<atom:link href="http://blog.mbischof.de/kategorie/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.mbischof.de</link>
	<description>yes it is - meine yiiframework snippets</description>
	<lastBuildDate>Thu, 02 Feb 2012 19:59:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>auto_increment setzen</title>
		<link>http://blog.mbischof.de/auto_increment-setzen</link>
		<comments>http://blog.mbischof.de/auto_increment-setzen#comments</comments>
		<pubDate>Mon, 16 May 2011 12:38:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.mbischof.de/?p=711</guid>
		<description><![CDATA[ALTER TABLE tablename AUTO_INCREMENT = 100]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> tablename <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">100</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.mbischof.de/auto_increment-setzen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alter berechnen</title>
		<link>http://blog.mbischof.de/alter-berechnen</link>
		<comments>http://blog.mbischof.de/alter-berechnen#comments</comments>
		<pubDate>Sat, 01 Aug 2009 02:59:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.mbischof.de/?p=317</guid>
		<description><![CDATA[SELECT TIMESTAMPDIFF&#40;YEAR, '1976-02-06', CURDATE&#40;&#41;&#41;]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">TIMESTAMPDIFF</span><span style="color: #FF00FF;">&#40;</span><span style="color: #9900FF; font-weight: bold;">YEAR</span><span style="color: #000033;">,</span> <span style="color: #008000;">'1976-02-06'</span><span style="color: #000033;">,</span> <span style="color: #000099;">CURDATE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.mbischof.de/alter-berechnen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eine Buddylist realisieren</title>
		<link>http://blog.mbischof.de/eine-buddylist-realisieren</link>
		<comments>http://blog.mbischof.de/eine-buddylist-realisieren#comments</comments>
		<pubDate>Thu, 19 Feb 2009 20:13:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.mbischof.de/?p=10</guid>
		<description><![CDATA[In jeder Community-Anwendung gehören Buddylisten zum Standard. Ich stelle Kontakt zu einem anderen User her und dieser bestätigt die Anfrage oder ignoriert sie. Wie man das in MySQL einfach umsetzt, zeige ich in diesem Beitrag. Man nehme zwei Tabellen: users (id, is_active, username) friends (request_user_id, response_user_id, status) Mein Userprofil ist in der Tabelle users hinterlegt. [...]]]></description>
			<content:encoded><![CDATA[<p>In jeder Community-Anwendung gehören Buddylisten zum Standard. Ich stelle Kontakt zu einem anderen User her und dieser bestätigt die Anfrage oder ignoriert sie. Wie man das in MySQL einfach umsetzt, zeige ich in diesem Beitrag.</p>
<p><span id="more-10"></span></p>
<p>Man nehme zwei Tabellen:</p>
<ul>
<li>users (id, is_active, username)</li>
<li>friends (request_user_id, response_user_id, status)</li>
</ul>
<p>Mein Userprofil ist in der Tabelle users hinterlegt. Die Tabelle friends erfaßt meine Kontaktanfragen und deren Status.<br />
Ich kann einerseits request_user_id sein, wenn ich die Kontaktanfrage starte, oder response_user_id, wenn ich eine Kontaktanfrage eines anderen Users beantworten soll.<br />
Der Status kann folgende Werte annehmen:</p>
<ul>
<li>0 = neu|offen</li>
<li>1 = bestätigt</li>
<li>2 = ignorieren|abgelehnt|zurückgenommen</li>
</ul>
<p>Ich habe die user_id = 589 und kann meine Buddies nun wie folgt abfragen:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span>
<span style="color: #66cc66;">&#40;</span>
  <span style="color: #993333; font-weight: bold;">SELECT</span> request_user_id <span style="color: #993333; font-weight: bold;">AS</span> friend_id <span style="color: #993333; font-weight: bold;">FROM</span> friends <span style="color: #993333; font-weight: bold;">WHERE</span> response_user_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">589</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>
    <span style="color: #993333; font-weight: bold;">UNION</span>
  <span style="color: #993333; font-weight: bold;">SELECT</span> repsonse_user_id <span style="color: #993333; font-weight: bold;">AS</span> friend_id <span style="color: #993333; font-weight: bold;">FROM</span> friends <span style="color: #993333; font-weight: bold;">WHERE</span> request_user_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">589</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>
<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> buddies
&nbsp;
<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> users <span style="color: #993333; font-weight: bold;">AS</span> u <span style="color: #993333; font-weight: bold;">ON</span> u<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> buddies<span style="color: #66cc66;">.</span>friend_id <span style="color: #993333; font-weight: bold;">WHERE</span> is_active <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span></pre></div></div>

<p>wir lesen diese Abfrage mal von innen nach aussen:</p>
<ul>
<li>Gib mir alle Datensätze, wo ich angefragt habe</li>
<li>Gib mir alle Datensätze, wo ich angefragt worden bin</li>
<li>Vereinige beide Mengen und nenne diese Menge &#8220;buddies&#8221;</li>
</ul>
<p>Ich bekomme eine Art neue Tabelle mit dem Namen &#8220;buddies&#8221; und einer Spalte &#8220;friend_id&#8221;<br />
Der INNER JOIN liefert alle Datensätze, die in beiden Mengen vorhanden sind, sowohl in der users-Tabelle als auch in der buddies Menge.</p>
<p>Ich hoffe, ich konnte das einigermaßen rüberbringen. Auf Wiedersehen!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mbischof.de/eine-buddylist-realisieren/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

