Add row after every rows of a table from select statement There are two tables. I want to add every record of one table under every record of the other table. The two tables and the result table are shown below.

TABLE_1    TABLE_2     TABLE_3
TYPE        NAME        NAME      TYPE  VALUE
T_1         PARTY_1     PARTY_1   T_1    100
T_2         PARTY_2     PARTY_1   T_2    200   
                        PARTY_2   T_1    120
RESULT_TABLE
RESULT     VALUE
PARTY_1     -
  T_1       100
  T_2       200
PARTY_2     -
  T_1       120
  T_2        0


How to do it? I am using SQLite database.

I have done so far ...

string qry = "SELECT " +
            "[TABLE_2].[NAME] AS [RESULT] " +
            "FROM [TABLE_2] " +
            "UNION " +
            "SELECT " +
            "'  - ' || [TABLE_1].[TYPE] " +
            "FROM [TABLE_1]";


But it shows as per below...

RESULT
PARTY_1
PARTY_2
- T_1
- T_2
Your question says two tables but your example shows three.  I'm going to take table_3 as the association table between table_1 and table_2, showing data which actually exists.

To get all possible combinations of two tables you need a CROSS JOIN. The number of rows returned is the product of the number or rows in each table. Be careful as this can get very large.  With two rows in each table you get four rows from a cross join.  With one thousand rows in each you get one million rows returned:

table_1 CROSS JOIN table_2


That will give you all possible combinations.  To include your actual values you will need a LEFT JOIN from that to table_3:

table_2 AS t2 CROSS JOIN table_1 AS t1
  LEFT JOIN table_3 AS t3
    ON  t3.name = t2.name
    AND t3.type = t1.type


If you want the extra "party" rows, you'll need one more subquery, combined with UNION to the previous one and all wrapped in an extra derived table to have the results in the wanted ordering. The final query will be something like:

SELECT 
    result, value
FROM
  ( SELECT
        name, name AS result, NULL AS value, 0 AS ordering
    FROM
        table_2

    UNION ALL

    SELECT
        t2.name, '  - ' || t1.type, COALESCE(t3.value, 0), 1
    FROM
        table_2 AS t2 CROSS JOIN table_1 AS t1
          LEFT JOIN table_3 AS t3
            ON  t3.name = t2.name
            AND t3.type = t1.type
  ) AS x 
ORDER BY
    name, ordering, result ;