unionmethods take either a Query Builder instance or a closure which you use to define a new QueryBuilder instance.
unionmethods are invoked, but the
unionstatements can be in any order in your API call stack. This means you can safely declare your
unionmethod calls before the
orderBycalls on the source Query Builder instance.
union()— This method builds a SQL statement using the
UNIONclause which combines two SQL queries into a single result set containing all the matching rows. The two queries must have the same defined columns and compatible data types or the SQL engine will generate an error. The
unionclause only returns unique rows.
unionAll()— This builds a SQL statement using the
UNION ALLclause. This is the same as
unionbut includes duplicate rows.
unionAllstatements will append it to the query.