select concat(v1.pronoun,' ',v2.verb,' ',v3.object, ' :-)' ) as sentence
from
(select 1 as id,'She' as pronoun union select 2 ,
'I' union select 3 ,'He' ) v1
left outer join
(select 1 as id,'like' as verb union select 2 ,
'likes' union select 3 ,'hates' ) v2
on (v1.id > v2.id)
left outer join
(select 1 as id,'chocolade' as object union select 2 ,
'playing' union select 3 ,'sql' ) v3
on (v1.id < v3.id)
having sentence is not null ;
a) She likes chocolade :-) b) He hates playing :-) c) I like sql :-)
[ Just for fun ]
Result:
This query is a little unusual:
v1,v2andv3are subqueries in theFROM-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
CONCATis null, then theCONCATwill returnNULL.Usually
HAVINGis used together withGROUP BY, but it also works without.