# UNION and UNION ALL in Looker

**URL:** <https://discuss.google.dev/t/union-and-union-all-in-looker/119169>\
**Category:** Technical Tips & Tricks\
**Created:** [May 11, 2022, 6:27pm UTC](https://discuss.google.dev/t/union-and-union-all-in-looker/119169 "2022-05-11T18:27:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [May 11, 2022, 6:27pm UTC](https://discuss.google.dev/t/union-and-union-all-in-looker/119169/1 "2022-05-11T18:27:50Z")

</div>

You can execute a SQL `UNION` or `UNION ALL` operator in both [SQL-based derived tables (DT)](https://docs.looker.com/data-modeling/learning-lookml/derived-tables#regular_or_%E2%80%9Cephemeral%E2%80%9D_derived_table) and [persistent derived tables (PDT)](https://docs.looker.com/data-modeling/learning-lookml/derived-tables#persistent_derived_table). The `UNION` and `UNION ALL` operators combine the result sets of two queries.

This example shows what a SQL-based DT looks like with a `UNION` in LookML:

```auto
view: union_example {    
  derived_table: {     
  sql: 
  SELECT 1 AS my_int      
  FROM union_example1 
  UNION      
  SELECT 2 AS my_int 
       FROM union_example2 ;;     
  }
}

```

This results in a derived table that combines the results of both queries.

The difference between `UNION` and `UNION ALL` is that `UNION ALL` does not remove duplicate rows. There are performance considerations to keep in mind when using `UNION` vs. `UNION ALL`, because the database server must do additional work to remove the duplicate rows. However, you usually do not want the duplicates.
