Method: Sequel::Dataset#union
- Defined in:
- lib/sequel/dataset/query.rb
#union(dataset, opts = OPTS) ⇒ Object
Adds a UNION clause using a second dataset object. A UNION compound dataset returns all rows in either the current dataset or the given dataset. Options:
- :alias
-
Use the given value as the from_self alias
- :all
-
Set to true to use UNION ALL instead of UNION, so duplicate rows can occur
- :from_self
-
Set to false to not wrap the returned dataset in a from_self, use with care.
DB[:items].union(DB[:other_items])
# SELECT * FROM (SELECT * FROM items UNION SELECT * FROM other_items) AS t1
DB[:items].union(DB[:other_items], :all=>true, :from_self=>false)
# SELECT * FROM items UNION ALL SELECT * FROM other_items
DB[:items].union(DB[:other_items], :alias=>:i)
# SELECT * FROM (SELECT * FROM items UNION SELECT * FROM other_items) AS i
884 885 886 |
# File 'lib/sequel/dataset/query.rb', line 884 def union(dataset, opts=OPTS) compound_clone(:union, dataset, opts) end |