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
2
votes
2 answers

Return data from multiple child tables in same row

I've some tables related by foreign keys from where I need to get data from, their structure is something like: Table A Intermediate A Child A | id | Data | idTableA | idChildA | id | Child A | 1 |…
2
votes
0 answers

NULLIF truncating date values only when in a UNION ALL Statement in MySql

I am using a statement similar to this to union the results to two similar tables. select sale_time, nullif(sale_time, '0000-00-00') as 'nullif_sale_time' from tblCompletedSales union all select sale_time, nullif(sale_time, '0000-00-00') as…
bconrad
  • 402
  • 4
  • 14
2
votes
1 answer

MySql Union Immediate Merge to Parent table ID

Thanks in advance. Am trying to merge two table into one. The below query returns the result that i want. Am aware UNION ALL will combine more than one tables. But i want to merge two table rows immediately after its parent row. SELECT …
2
votes
3 answers

MySQL: Optimizing SELECT from 6 huge identical tables with different data split up by timestamp

please I have the same problem as I found here MySQL - Selecting data from multiple tables all with same structure but different data , I have to select data from many MySQL tables with identical structure, but different data (split up into table_0,…
Cogicero
  • 1,514
  • 2
  • 17
  • 36
2
votes
1 answer

unionAll in spark SQL goes on hang

I am having two data sets received after OLTP/OLAP processing , though these two data sets contains same field but while fetching the same they varies in their schema say by field being Null or Not Null. To explain in detail say I have df1 and…
Prashant Agrawal
  • 381
  • 3
  • 14
2
votes
1 answer

Alasql: UNION (or UNION ALL) only gives results from table1

When using UNION or UNION ALL in a GROUP BY query using alasql (https://github.com/agershun/alasql), only results from table1 are retrieved. Running separate queries outputs correct results instead. See this jfiddle…
MDT
  • 1,599
  • 4
  • 18
  • 26
2
votes
2 answers

Does table1 UNION ALL table2 guarantee output order table1, table2?

SELECT a FROM b UNION ALL SELECT a FROM c UNION ALL SELECT a FROM d Does UNION ALL guarantee to print out records from tables b, c, d in that order? I.e., no records from c before any from b. This question is not for a specific DBMS.
u17
  • 2,776
  • 4
  • 31
  • 43
2
votes
2 answers

Grouping 2 Tables without join on in MySQL

This might sound confusing but here is what I am trying to achieve... I have two tables with some common columns that I would like to group them into one view... (I dont Have any unique COLUMN) Table 1: PatientID Name Grade x Grade Y …
Mohamed Mahyoub
  • 381
  • 2
  • 18
2
votes
4 answers

UNION ALL on 3 tables with different number of columns in each table - how to do so efficiently

I wanted to use UNION ALL on 3 different tables, merging them into one table by using SELECT INTO. Table 1 ,2 and 3 has 15, 7 and 8 columns respectively. So, was there a way for me to use UNION ALL and have table 2 and 3 default to a NULL for the…
elbarto
  • 211
  • 3
  • 15
2
votes
2 answers

Psql - sub queries in from clause - bad practice?

The task at hand is to select musicians (pid) and the amount of instruments each play, including instruments only played at a concert - these instruments might not be in the [plays] table. I've solved it, but I read that sub queries in a from clause…
prideHURTS
  • 43
  • 1
  • 5
2
votes
0 answers

Google BigQuery: Query too large, part 2

Can the GBQ team share more about why the "Query too large" error might be popped? And also more workarounds for the problem I experienced: In particular, I will give more details of what I was doing when it popped and some of the resolutions that…
JBarrera
  • 56
  • 4
2
votes
2 answers

How to limit the result of UNION ALL query?

I have a query like this: select col1, col2 from table1 where col1 = ? union all select col1, col2 from table2 where col2 = ? Now I need to limit the result of the above query, Now I want to know, if I use limit clause after second select, then…
stack
  • 10,280
  • 19
  • 65
  • 117
2
votes
2 answers

UNION ALL on 2 tables select with Cases

I'm running SQL Server 2005. I have 2 tables with the same columns but holding very different data. SELECT * FROM Table1 WHERE ItemID IN ('4','2','1') ORDER BY CASE WHEN ItemID = 4 then 1 WHEN ItemID = 2 then 2 WHEN ItemID = 1 then 3 END…
Steve
  • 75
  • 1
  • 9
2
votes
1 answer

SQLite: UNION of n places ORDER BY size together with all the capitals?

I try to select from ne_10m_populated_places both the 15 biggest cities together with the 3~5 ones where FEATURECLA='Admin-0 capital' (the countries capitals). So for my area, I should get back ~18-20 places. I'am very beginner to SQL, and don't…
Hugolpz
  • 17,296
  • 26
  • 100
  • 187
2
votes
1 answer

group by on union all result SQL Server

I am new to SQL Server. I have a SQL query where I performed an union all, the 2 individual queries have group by. select top 5 Starttime, convert(date,row_date) as Date, sum(acdcalls + abncalls) [Offered], sum(acdcalls) [Handled], …
Karthik
  • 23
  • 1
  • 4