Question: **First Query**:(I have added count(\*) for simplification)

```
select count(*) from Sales_order_line sol
where
sol.grant_type_id is null
AND
 sol.quantity  - NVL ((SELECT SUM (salesorder15_.assigned_quantity) FROM license_link_sales_ord_ln salesorder15_  
 WHERE salesorder15_.sales_order_line_id = sol.ID),0) > 0;

```

**Second Query**:(I have added count(\*) for simplification)

```
select count(*) from Sales_order_line sol
INNER JOIN license_link_sales_ord_ln sola
ON sol.id=sola.sales_order_line_id
where
sol.grant_type_id is null;

```

The first query returns **56119** and second one returns **362260**. I want to combine the queries which gives me **(56119 +362260)** as result.

Answer: 
To union the queries together with different numbers of columns you need to fill the columns that are not the same (don't match in both queries) with null as shown below:

```
SELECT columnA, columnB, columnC, columnD, columnE
FROM Sales_order_line s
WHERE s.grant_type_id IS NULL
AND s.quantity  - NVL ((SELECT SUM (so.assigned_quantity) 
                        FROM license_link_sales_ord_ln so
                        WHERE so.sales_order_line_id = s.ID),0) > 0
UNION ALL
SELECT columnA, columnB, columnC, null, null
FROM Sales_order_line s
INNER JOIN license_link_sales_ord_ln l ON s.id = l.sales_order_line_id
WHERE s.grant_type_id IS NULL;

```
Use `UNION ALL`

```
SELECT count(*) 
FROM Sales_order_line s
WHERE s.grant_type_id IS NULL
AND s.quantity  - NVL ((SELECT SUM (so.assigned_quantity) 
                        FROM license_link_sales_ord_ln so
                        WHERE so.sales_order_line_id = s.ID),0) > 0
UNION ALL
SELECT count(*)
FROM Sales_order_line s
INNER JOIN license_link_sales_ord_ln l ON s.id = l.sales_order_line_id
WHERE s.grant_type_id IS NULL;

```