<?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 Question of the Day</title>
	<atom:link href="http://mysql-qotd.casperia.net/feed" rel="self" type="application/rss+xml" />
	<link>http://mysql-qotd.casperia.net</link>
	<description>mysql 5.0/5.1 questions for learning purposes</description>
	<lastBuildDate>Fri, 06 Aug 2010 16:42:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Question 85: What is the result of the query?</title>
		<link>http://mysql-qotd.casperia.net/archives/562</link>
		<comments>http://mysql-qotd.casperia.net/archives/562#comments</comments>
		<pubDate>Fri, 06 Aug 2010 16:41:45 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[mysql questions]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[question]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=562</guid>
		<description><![CDATA[

select n,n and 3,n &#038; 3, n mod 4, n and false,n and true
from (select 0 n union select 1 union select 2 union
      select 3 union select 4 union select 5 union
      select 6 union select 7 union select null) v1;


&#160;
Hints:
The subquery v1 returns [...]]]></description>
			<content:encoded><![CDATA[<p><small>
<pre>
select n,n and 3,n &#038; 3, n mod 4, n and false,n and true
from (select 0 n union select 1 union select 2 union
      select 3 union select 4 union select 5 union
      select 6 union select 7 union select null) v1;
</pre>
<p></small><br />
&nbsp;<br />
Hints:<br />
The subquery v1 returns column n with the rows 0,1,2,3,4,5,6,7,null.<br />
&#8220;&#038;&#8221; is the binary and-operation. &#8220;MOD&#8221; is the modulo (remainder) calculation.<br />
Mysql treats 0 as false and anything else as true.<br />
The constants TRUE and FALSE have the values 1 and 0.</p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/562/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More uncommon SQL</title>
		<link>http://mysql-qotd.casperia.net/archives/560</link>
		<comments>http://mysql-qotd.casperia.net/archives/560#comments</comments>
		<pubDate>Sun, 25 Jul 2010 19:55:11 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[general]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=560</guid>
		<description><![CDATA[Hi again!
The query below uses quite a bit of strange looking SQL syntax:


select all
  count(1) minus
union all
  select 1 only
order by 1 limit 1  ;

+-------+
&#124; minus &#124;
+-------+
&#124;     1 &#124;
+-------+
1 row in set (0.00 sec)


&#160;
The &#8220;ALL&#8221; in the &#8220;SELECT ALL&#8221; is actually the default &#8211; so you hardly ever [...]]]></description>
			<content:encoded><![CDATA[<p>Hi again!<br />
The query below uses quite a bit of strange looking SQL syntax:<br />
<small>
<pre>
select all
  count(1) minus
union all
  select 1 only
order by 1 limit 1  ;

+-------+
| minus |
+-------+
|     1 |
+-------+
1 row in set (0.00 sec)
</pre>
<p></small><br />
&nbsp;<br />
The &#8220;ALL&#8221; in the &#8220;SELECT ALL&#8221; is actually the default &#8211; so you hardly ever see it.<br />
&#8220;COUNT(1)&#8221; is mostly used with Oracle, where it may have a performance benefit over &#8220;COUNT(*)&#8221;. The result however is the same than &#8220;COUNT(*)&#8221;.<br />
The &#8220;minus&#8221; and &#8220;only&#8221; are column aliases.<br />
Last but not least, the &#8220;ORDER BY 1&#8243; means, that we order by the first column.</p>
<p>Below the same slightly more readable:<br />
<small>
<pre>
select
  count(*) as cnt
union all
  select 1
order by cnt limit 1  ;
</pre>
<p></small></p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/560/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uncommon SQL 3</title>
		<link>http://mysql-qotd.casperia.net/archives/556</link>
		<comments>http://mysql-qotd.casperia.net/archives/556#comments</comments>
		<pubDate>Wed, 21 Jul 2010 16:57:33 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[general]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=556</guid>
		<description><![CDATA[Hello!
The following query does the same than yesterday&#8217;s, featuring another syntax which isn&#8217;t used that often.


MariaDB [tt]> select * from vending_price
where (price,product_id) = any (select max(price),product_id
                              [...]]]></description>
			<content:encoded><![CDATA[<p>Hello!<br />
The following query does the same than yesterday&#8217;s, featuring another syntax which isn&#8217;t used that often.<br />
<small>
<pre>
MariaDB [tt]> select * from vending_price
where (price,product_id) = any (select max(price),product_id
                                            from vending_price
                                            group by product_id);
</pre>
<p></small></p>
<p>The &#8220;ANY/ALL&#8221; syntax can be very intuitive for some queries&#8230; Unluckliy not for this example %)</p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/556/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uncommon SQL 2</title>
		<link>http://mysql-qotd.casperia.net/archives/553</link>
		<comments>http://mysql-qotd.casperia.net/archives/553#comments</comments>
		<pubDate>Tue, 20 Jul 2010 14:19:18 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[general]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=553</guid>
		<description><![CDATA[Hi again!
Continuing the example from yesterday, the following query shows the the real power of that syntax:


MariaDB [tt]> select * from vending_price where (price,product_id) in
                      (select max(price),product_id
        [...]]]></description>
			<content:encoded><![CDATA[<p>Hi again!<br />
Continuing the example from yesterday, the following query shows the the real power of that syntax:<br />
<small>
<pre>
MariaDB [tt]> select * from vending_price where (price,product_id) in
                      (select max(price),product_id
                       from vending_price group by product_id);
</pre>
<p></small></p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/553/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uncommon SQL</title>
		<link>http://mysql-qotd.casperia.net/archives/549</link>
		<comments>http://mysql-qotd.casperia.net/archives/549#comments</comments>
		<pubDate>Mon, 19 Jul 2010 19:03:49 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[general]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=549</guid>
		<description><![CDATA[Hi!
There are some useful SQL structures, which are not so commonly used. For example I like the following syntax:


select * from vending_price where (product_id,valid_from) = (0,'2010-01-09');

It is basically the same than the following, but more compact and easier to read.

select * from vending_price where product_id = 0 and valid_from  =  '2010-01-09';

 
]]></description>
			<content:encoded><![CDATA[<p>Hi!<br />
There are some useful SQL structures, which are not so commonly used. For example I like the following syntax:<br />
<small>
<pre>
select * from vending_price where (product_id,valid_from) = (0,'2010-01-09');</pre>
<p></small><br />
It is basically the same than the following, but more compact and easier to read.<small>
<pre>
select * from vending_price where product_id = 0 and valid_from  =  '2010-01-09';
</pre>
<p></small> </p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/549/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No questions for a while</title>
		<link>http://mysql-qotd.casperia.net/archives/543</link>
		<comments>http://mysql-qotd.casperia.net/archives/543#comments</comments>
		<pubDate>Wed, 14 Jul 2010 18:42:32 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[general]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=543</guid>
		<description><![CDATA[Hi!
I won&#8217;t be able to post questions for a while&#8230;
Lots of things to do and everybody else is on holiday.
And then soon I&#8217;ll be on holiday :)
CU! 
]]></description>
			<content:encoded><![CDATA[<p>Hi!<br />
I won&#8217;t be able to post questions for a while&#8230;<br />
Lots of things to do and everybody else is on holiday.<br />
And then soon I&#8217;ll be on holiday :)</p>
<p>CU! </p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/543/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Question 84: Which of the following are equivalent?</title>
		<link>http://mysql-qotd.casperia.net/archives/541</link>
		<comments>http://mysql-qotd.casperia.net/archives/541#comments</comments>
		<pubDate>Tue, 13 Jul 2010 17:20:39 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[mysql questions]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[question]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=541</guid>
		<description><![CDATA[1) where a in (1,2,3)
2) where a = 1 and a = 2 and a = 3
3) where b > 10 and b < 20
4) where a = 1 or a = 2 or a = 3
5) where b between 10 and 20
6) where b >= 10 and b < = 20
7) where b >= [...]]]></description>
			<content:encoded><![CDATA[<p>1) where a in (1,2,3)<br />
2) where a = 1 and a = 2 and a = 3<br />
3) where b > 10 and b < 20<br />
4) where a = 1 or a = 2 or a = 3<br />
5) where b between 10 and 20<br />
6) where b >= 10 and b < = 20<br />
7) where b >= 10 and b < 20<br />
&nbsp;<br />
Which of the following are equivalent?<br />
(Find all correct answers)<br />
&nbsp;<br />
a) 3 and 5<br />
b) 5 and 6<br />
c) 1 and 4<br />
d) 5 and 7<br />
e) 1 and 2<br />
&nbsp;<br />
[Just for fun]</p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/541/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Question 83: How to get the correct price?</title>
		<link>http://mysql-qotd.casperia.net/archives/537</link>
		<comments>http://mysql-qotd.casperia.net/archives/537#comments</comments>
		<pubDate>Mon, 12 Jul 2010 18:03:48 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[mysql questions]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[question]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=537</guid>
		<description><![CDATA[Extending on the scenario of Q80:
We want to read the correct historical price and sum up per product/day.
The price table is below&#8230;


drop table if exists vending_price ;
create table vending_price
  (product_id int,valid_from date,valid_to date,price decimal (8,2),
  primary key (product_id,valid_from,valid_to)) engine = innodb;
insert into vending_price
  select v1.product_id,v2.d,adddate(v2.d,interval 3 day),rand() * 15 from
   [...]]]></description>
			<content:encoded><![CDATA[<p>Extending on the scenario of Q80:<br />
We want to read the correct historical price and sum up per product/day.<br />
The price table is below&#8230;</p>
<p><small>
<pre>
drop table if exists vending_price ;
create table vending_price
  (product_id int,valid_from date,valid_to date,price decimal (8,2),
  primary key (product_id,valid_from,valid_to)) engine = innodb;
insert into vending_price
  select v1.product_id,v2.d,adddate(v2.d,interval 3 day),rand() * 15 from
    (select distinct product_id from vending_log) v1,
    (select '2010-01-01' as d union select '2010-01-05' union
     select '2010-01-09' union select '2010-01-13' union select '2010-01-17' ) v2;
</pre>
<p></small><br />
&nbsp;<br />
[Just for fun]</p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/537/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Question 82: More solutions for Q80?</title>
		<link>http://mysql-qotd.casperia.net/archives/535</link>
		<comments>http://mysql-qotd.casperia.net/archives/535#comments</comments>
		<pubDate>Sun, 11 Jul 2010 11:43:14 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[mysql questions]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[question]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=535</guid>
		<description><![CDATA[Hello again!
Still about question 80&#8230; We have now 3 solutions to read values from the previous row: Subquery, user variables and with a helper-table + join. There is another feature (at least) which could be used, maybe a more procedural way? (hint, hint)
&#160;
[Just for fun]
]]></description>
			<content:encoded><![CDATA[<p>Hello again!<br />
Still about question 80&#8230; We have now 3 solutions to read values from the previous row: Subquery, user variables and with a helper-table + join. There is another feature (at least) which could be used, maybe a more procedural way? (hint, hint)<br />
&nbsp;<br />
[Just for fun]</p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/535/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Question 81: More solutions for Q80?</title>
		<link>http://mysql-qotd.casperia.net/archives/533</link>
		<comments>http://mysql-qotd.casperia.net/archives/533#comments</comments>
		<pubDate>Sat, 10 Jul 2010 17:52:32 +0000</pubDate>
		<dc:creator>plogi</dc:creator>
				<category><![CDATA[mysql questions]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[question]]></category>

		<guid isPermaLink="false">http://mysql-qotd.casperia.net/?p=533</guid>
		<description><![CDATA[Hi!
It is really important to find as many different solutions as possible for a problem. The reason is, that sometimes a certain solution won&#8217;t work depending on the situation. So you need to have alternatives.
For question 80 I offered two possibilities, one with user-variables and one with a subquery. Are there more?
[Just for fun]  [...]]]></description>
			<content:encoded><![CDATA[<p>Hi!<br />
It is really important to find as many different solutions as possible for a problem. The reason is, that sometimes a certain solution won&#8217;t work depending on the situation. So you need to have alternatives.<br />
For question 80 I offered two possibilities, one with user-variables and one with a subquery. Are there more?</p>
<p>[Just for fun]  </p>
]]></content:encoded>
			<wfw:commentRss>http://mysql-qotd.casperia.net/archives/533/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

