Questions tagged [union-all]

"UNION ALL" is a keyword in SQL that is used for combining the results of multiple SELECTs. The related tag is "UNION". "UNION ALL" combines the results without checking for Uniqueness. "UNION" combines the results eliminating duplicates.

UNION ALL is a keyword in SQL that is used for combining the results of multiple SELECTs. The related tag is UNION (). UNION ALL combines the results without checking for uniqueness. UNION combines the results eliminating duplicates. The type and order of the fields in the two SELECTs should be the same.

775 questions
5
votes
2 answers

MySQL performance of VIEW for tables combined with UNION ALL

Let's say I have 2 tables in MySQL: create table `persons` ( `id` bigint unsigned not null auto_increment, `first_name` varchar(64), `surname` varchar(64), primary key(`id`) ); create table `companies` ( `id` bigint unsigned…
Yuriy Nakonechnyy
  • 3,742
  • 4
  • 29
  • 41
5
votes
5 answers

MSSQL - union all with different decimal precision

When I execute this SQL SELECT 1.4 UNION ALL SELECT 2.0400 union all SELECT 1.24 I get the following result: 1.4000 2.0400 1.2400 But when I execute the following SQL SELECT sum(1.4) UNION ALL SELECT sum(2.0400) union all SELECT sum(1.24) I get…
Armen Nazarian
  • 95
  • 1
  • 2
  • 5
5
votes
3 answers

Don't repeat yourself: same SQL query, but two different tables

I have an SQL query with exact the same code, but two different tables (AUDIT_TRAIL_ARCHIVE and AUDIT_TRAIL). I use "UNION ALL" to have one result. Good programmers use "Don't repeat yourself" principle. Good programmers avoid WET (write everything…
Sybil
  • 2,503
  • 3
  • 25
  • 36
5
votes
1 answer

How do I continue the process after inserting non-matching lookup rows into a table?

Inside a data flow, is it possible to do a lookup, insert the non-matching rows, re-lookup and then continue with the full (original) data set? I can't see how you get/re-use the inserted rows after they've gone to an OLE DB Destination, nor can I…
PeterX
  • 2,713
  • 3
  • 32
  • 42
4
votes
4 answers

Laravel fetch data from two tables without join with pagination

I want to fetch results from two tables properties and properties_x where properties.address or properties_x.address_x like test with laravel pagination. There is no foreign key relationship between these two tables. properties id name …
Harpal Singh
  • 694
  • 6
  • 27
4
votes
1 answer

SQL Server (2014) Odd behaviour from variations on IN (list)

I've been looking at trying to optimise (or at least change) some EF code in C# to use stored procedures, and found what seems to be an anomaly (or something new to me) when finding rows matching a constant list. The typical manually-generated short…
4
votes
2 answers

How to union SELECT two tables with ids of both tables?

Ok, I have four tables: Table 1: "f_withholdings" Table 2: "f_wh_list" Table 3: "f_rpayments" Table 4: "f_rp_list" Table 1 and Table 2 are connected with each other by wh_id field and Table 3 and Table 4 are connected by rp_id as seen in…
Darkhan
  • 1,258
  • 2
  • 13
  • 21
4
votes
2 answers

How does MySQL UNION ALL run agregate functions?

I have some SQL code which is working exactly how I want it to: select 10 as number, "Checklist 10 Foo" as name, max(id), max(ts) as max_ts, callsign, max(time_hint_utc), count(*) from checklist_10 union all select 11 as number, "Checklist 11 Bar"…
fadedbee
  • 42,671
  • 44
  • 178
  • 308
4
votes
3 answers

How can I display rows values in columns sql server?

SQL FIDDLE DEMO HERE I have this table structure for SheduleWorkers table: CREATE TABLE SheduleWorkers ( [Name] varchar(250), [IdWorker] varchar(250), [IdDepartment] int, [IdDay] int, [Day]…
Esraa_92
  • 1,558
  • 2
  • 21
  • 48
4
votes
1 answer

How to union tables with different schema in HIVE?

I have two tables in HIVE: table A, which contains a column "N" which is of type array table B, in which column "N" does not appear both tables A and B contain column "C". I'd like to union them like this: select g.* from (select N, C from…
makansij
  • 9,303
  • 37
  • 105
  • 183
4
votes
1 answer

MS Access SQL: Using SELECT INTO with a UNION ALL query

I'm attempting to turn an already working UNION query into a SELECT INTO as part of a VBA procedure for a bunch of temp tables. I'm doing this because Access is having performance issues. When I try to run this query with the INTO clauses inserted,…
plankton
  • 369
  • 5
  • 21
4
votes
1 answer

UNION multiple MDX queries in SSAS (powerpivot)

I have some sort of difficulties trying to join 2 MDX queries together. When running them separately they work fine. The script below WITH MEMBER [Measures].[ParameterCaption] AS [Main_Incidents].[Priority].CurrentMember.Member_Caption …
PeddiePooh
  • 403
  • 8
  • 17
4
votes
2 answers

SSIS Union All does not return all the records

Very beginner question please. I have a simple script that performs a lookup for records in a different table - in this case the doctor who was assigned for treatments of a patient. Due to the lack of data quality control, a number of records do not…
theUnderdog
  • 105
  • 1
  • 1
  • 8
4
votes
2 answers

MS VBA with loops and unions

Dim Counter As Integer Dim Maxhouse As Integer Dim FindHouse As Range Dim RangeVar As Range Dim HousesRange As Range For Counter = 1 To MaxHouse ActiveSheet.Cells(16, 2 + Counter).Select House = ActiveCell With…
user3072955
  • 43
  • 1
  • 6
4
votes
3 answers

Union in JPA query - from the same table

I have a requirement where I need to restrict number of records returned from a table for a particular flag and all records for the other flag value. For example: contact-history table has an element called IorM_flg with possible values 'm' and…
Kevin Rave
  • 13,876
  • 35
  • 109
  • 173
1 2
3
51 52