In MySQL 8.0+ using ROW_NUMBER() window function in each table to get a row number and join the tables on that for row to column transformation from different tables (pivot-table)
The function working correctly if the 2 tables have the same number of rows, like your sample data.
WITH
cte1 AS (SELECT *, ROW_NUMBER() OVER (ORDER BY sID) rn FROM t_contents_q400),
cte2 AS (SELECT *, ROW_NUMBER() OVER (ORDER BY sID) rn FROM t_contents_q410)
SELECT
c1.contents Q400,
c2.contents Q410
FROM cte1 c1
INNER JOIN cte2 c2 ON c2.rn = c1.rn;
+-----------------------+-----------------------+
| Q400 | Q410 |
+-----------------------+-----------------------+
| Set n.1 | Set n.1 |
| - Par 1.1 | - Par 1.1 |
| <b>bold text</b> | <b>bold text</b> |
| - Par 1.2 | - Par 1.2 |
| normal text | normal text |
| Set n.2 | Set n.2 |
| - Par 2.1 | - Par 2.1 |
| <i>italic text</i> | <i>italic text</i> |
| - Par 2.2 | - Par 2.2 |
| <u>underline text</u> | <u>underline text</u> |
| - Par 2.3 | - Par 2.3 |
+-----------------------+-----------------------+
11 rows in set (0.03 sec)
But if the 2 tables have the different number of rows some rows are not merged.
On my case I have in the first table t_contents_q400
14 rows total and in the second table t_contents_q410
I have 11 rows total.
On the return these rows of the first table t_contents_q400
are not extract.
Set n.3 Q400
- Par 3.1 Q400
<i>text</i> Q400
My structures and data tables below
-- ----------------------------
-- Table structure for t_contents_q400
-- ----------------------------
DROP TABLE IF EXISTS `t_contents_q400`;
CREATE TABLE `t_contents_q400` (
`contents` varchar(255) DEFAULT NULL,
`sUnity` varchar(50) DEFAULT NULL,
`sID` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`sID`) USING BTREE,
UNIQUE INDEX `contents`(`contents`, `sUnity`) USING BTREE
) ENGINE = InnoDB;
-- ----------------------------
-- Records of t_contents_q400
-- ----------------------------
INSERT INTO `t_contents_q400` VALUES ('- Par 1.1', 'Q400', 1);
INSERT INTO `t_contents_q400` VALUES ('- Par 1.2', 'Q400', 2);
INSERT INTO `t_contents_q400` VALUES ('- Par 2.1', 'Q400', 3);
INSERT INTO `t_contents_q400` VALUES ('- Par 2.2', 'Q400', 4);
INSERT INTO `t_contents_q400` VALUES ('- Par 2.3', 'Q400', 5);
INSERT INTO `t_contents_q400` VALUES ('- Par 3.1', 'Q400', 6);
INSERT INTO `t_contents_q400` VALUES ('<b>bold text</b>', 'Q400', 7);
INSERT INTO `t_contents_q400` VALUES ('<i>italic text</i>', 'Q400', 8);
INSERT INTO `t_contents_q400` VALUES ('<i>text</i>', 'Q400', 9);
INSERT INTO `t_contents_q400` VALUES ('<u>underline text</u>', 'Q400', 10);
INSERT INTO `t_contents_q400` VALUES ('normal text', 'Q400', 11);
INSERT INTO `t_contents_q400` VALUES ('Set n.1', 'Q400', 12);
INSERT INTO `t_contents_q400` VALUES ('Set n.2', 'Q400', 13);
INSERT INTO `t_contents_q400` VALUES ('Set n.3', 'Q400', 14);
-- ----------------------------
-- Table structure for t_contents_q410
-- ----------------------------
DROP TABLE IF EXISTS `t_contents_q410`;
CREATE TABLE `t_contents_q410` (
`contents` varchar(255) DEFAULT NULL,
`sUnity` varchar(50) DEFAULT NULL,
`sID` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`sID`) USING BTREE,
UNIQUE INDEX `contents`(`contents`, `sUnity`) USING BTREE
) ENGINE = InnoDB;
-- ----------------------------
-- Records of t_contents_q410
-- ----------------------------
INSERT INTO `t_contents_q410` VALUES ('- Par 1.1', 'Q410', 1);
INSERT INTO `t_contents_q410` VALUES ('- Par 1.2', 'Q410', 2);
INSERT INTO `t_contents_q410` VALUES ('- Par 2.1', 'Q410', 3);
INSERT INTO `t_contents_q410` VALUES ('- Par 2.2', 'Q410', 4);
INSERT INTO `t_contents_q410` VALUES ('- Par 2.3', 'Q410', 5);
INSERT INTO `t_contents_q410` VALUES ('<b>bold text</b>', 'Q410', 6);
INSERT INTO `t_contents_q410` VALUES ('<i>italic text</i>', 'Q410', 7);
INSERT INTO `t_contents_q410` VALUES ('<u>underline text</u>', 'Q410', 8);
INSERT INTO `t_contents_q410` VALUES ('normal text', 'Q410', 9);
INSERT INTO `t_contents_q410` VALUES ('Set n.1', 'Q410', 10);
INSERT INTO `t_contents_q410` VALUES ('Set n.2', 'Q410', 11);