Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php:4991) in /www/htdocs/v030397/mysql-qotd/wp-includes/feed-rss2-comments.php on line 8
Comments on: Qustion 14: What will the following query return? http://mysql-qotd.casperia.net/archives/172 mysql 5.0/5.1 questions for learning purposes Fri, 06 Aug 2010 16:56:36 +0000 http://wordpress.org/?v=abc hourly 1 By: urs http://mysql-qotd.casperia.net/archives/172/comment-page-1#comment-20 urs Wed, 10 Feb 2010 19:00:17 +0000 http://mysql-qotd.casperia.net/?p=172#comment-20 <strong>   Result: <pre>+---------------+ | sentence | +---------------+ | I like sql :) | +---------------+ 1 row in set (0.03 sec)</pre>   This query is a little unusual: <code>v1</code>, <code>v2</code> and <code>v3</code> are subqueries in the <code>FROM</code>-clause. They act like tables with 2 columns and 3 rows each.   Because they are left joined, nulls are returned, which are then filtered out with the <code>HAVING</code>-clause. If one of the arguments in a <code>CONCAT</code> is null, then the <code>CONCAT</code> will return <code>NULL</code>. Usually <code>HAVING</code> is used together with <code>GROUP BY</code>, but it also works without. </strong>  
 
Result:

+---------------+
| sentence      |
+---------------+
| I like sql :) |
+---------------+
1 row in set (0.03 sec)

 
This query is a little unusual:
v1, v2 and v3 are subqueries in the FROM-clause. They act like tables with 2 columns and 3 rows each.
 
Because they are left joined, nulls are returned, which are then filtered out with the HAVING-clause.
If one of the arguments in a CONCAT is null, then the CONCAT will return NULL.
Usually HAVING is used together with GROUP BY, but it also works without.

 

]]>