This query has two subqueries in the FROM-clause: a and b.
Subquery b results in
+---+
| a |
+---+
| 1 |
+---+
And a results in
+---+
| b |
+---+
| 1 |
| 2 |
+---+
We select column a from subquery b and give it the alias b.
This explains the ‘b’ as the column name in the result.
The subqueries are joined together without any restriction:
There is no on-clause or where-clause. That means, the result has 1 * 2 rows (cartesian product join).
This query is syntactically a bit confusing, but I hope it helps understanding subqueries, aliases and joins.
MariaDB [mysql]> select a b from (select 1 a) b, (select 1 b union select 2) a; a) +---+ | b | +---+ | 1 | | 1 | +---+ 2 rows in set (0.00 sec)]]>