union-all Questions

6

Solved

I have to run a SELECT statement across several tables. I am sure the tables return different records. I am anyway using UNION ALL. Is it better to use UNION or of UNION ALL in performance terms wh...
Nomenclator asked 2/9, 2010 at 14:12

6

Solved

I found this sample interview question and answer posted on toptal reproduced here. But I don't really understand the code. How can a UNION ALL turn into a UNIION (distinct) like that? Also, why is...
Thermos asked 18/1, 2017 at 20:43

4

Solved

i have two queries being combined with a UNION ALL1: --Query 1 SELECT Flavor, Color FROM Friends   --Query 2 SELECT Flavor, (SELECT TOP 1 Color FROM Rainbows WHERE Rainbows.StrangerID =...
School asked 10/9, 2010 at 14:45

1

Solved

I'm running a complex stored procedure and I'm getting an error when I have 3 unions, but with 2 unions no error. If I remove either of the top two unions it runs fine. If I make one of the NULLs a...
Ind asked 21/9, 2020 at 17:34

2

Solved

I have 600 tables to perform a UNION ALL query on. Unfortunately the order of the columns in each table varies, however they will always have the same name - example: Table 1 Item, Cost, ID, Cod...
Delightful asked 15/4, 2020 at 15:38

2

Solved

I have a query with a UNION clause. One of the field is a plain hardcoded string. The string in the statement after UNION gets truncated to match the string length of the field before the UNION. S...
Groan asked 26/11, 2014 at 22:19

2

Solved

I have three queries with results. Query 1: SELECT DISTINCT employeeid, work.clientid, ROUND ((CAST (AVG(current_lawn_price) AS numeric) / CAST (AVG((((EXTRACT(HOUR FROM job_finish)*60) + EXTRACT...
Threnody asked 15/12, 2019 at 22:50

19

Solved

What is the difference between UNION and UNION ALL?
Astigmia asked 8/9, 2008 at 15:19

10

Solved

UNION joins two results and remove duplicates, while UNION ALL does not remove duplicates. UNION also sort the final output. What I want is the UNION ALL without duplicates and without the sort. I...
Headquarters asked 26/9, 2011 at 7:47

2

Solved

UNION and UNION ALL queries can outperform equivalent queries using OR-connected predicates under certain circumstances. To my knowledge, this is partially because UNION subselects can be executed ...
Anaximenes asked 8/5, 2012 at 7:11

3

Solved

I'm trying to wrap my head around these two functions in the Spark SQL documentation– def union(other: RDD[Row]): RDD[Row] Return the union of this RDD and another one. def unionAll(otherPlan: S...
Duckweed asked 12/3, 2015 at 23:56

4

Solved

How can I get first record of a table and last record of a table in one result-set? This Query fails SELECT TOP 1 Id,Name FROM Locations ORDER BY Id UNION ALL SELECT TOP 1 Id,Name FROM Locations ...
Lengel asked 5/4, 2011 at 11:27

5

I need help also about paging and using UNION ALL for multiple tables: How do i implement an optimized paging when joining multiple tables using UNION ALL and returning only specific number of row...
Brotherly asked 6/6, 2013 at 17:12

1

This is pretty complicated for a person just learning Linq! I asked how to JOIN and GROUP BY in this question and a BIG SHOUT OUT to TriV for his explicit and very helpful answer. Now, I want to t...
Meek asked 5/5, 2017 at 20:2

3

Solved

In the following query I get syntax error: SELECT <property1>, <property2> FROM <table1> ORDER BY <condition> LIMIT 1 UNION ALL SELECT <property1>, <property2>...
Dagda asked 20/5, 2016 at 17:14

3

Solved

I want to use union all with manual value, not from another table. And the values are: |cSatuan1|cSatuan2|nkonversi| ============================= | LTR | PCS | 1 | | PCS | LTR | 1 | I've made t...
British asked 24/5, 2012 at 7:27

1

Solved

I want to create a DataFrame from a list of string that could match existing schema. Here is my code. val rowValues = List("ann", "f", "90", "world", "23456") // fails val rowValueTuple = ("ann...
Lorraine asked 21/4, 2016 at 12:9

1

Solved

Disclaimer: I'm in the process of learning SSIS - so forgive me if this is an obvious answer, but I couldn't find anything on searching. It seems that the Merge transformation is very similar to t...
Artemisa asked 22/3, 2016 at 7:14

8

I have a DB view which basically consists of two SELECT queries with UNION ALL, like this: CREATE VIEW v AS SELECT time, etc. FROM t1 // #1... UNION ALL SELECT time, etc. FROM t2 // #2... The pr...
Hooks asked 27/1, 2012 at 9:25

3

Solved

What is the expected behaviour due to SQL Standard when we perform UNION on two tables with different data types: create table "tab1" ("c1" varchar(max)); create table "tab2" ("c3" integer); inser...
Dael asked 5/5, 2015 at 9:45

1

Solved

I have a stored procedure with the following query: SELECT (sum(addition)) AS [COUNT], MAX(CONVERT(VARCHAR(12),CREATED,102)) as [date] FROM [TABLE_ONE] WHERE convert(VARCHAR(12),CREATED,102) BETW...
Filar asked 7/1, 2015 at 11:59

5

Solved

I was going through union and union all logic and trying examples. What has puzzled me is why is it necessary to have same number of columns in both the tables to perform a union or union all opera...
Party asked 31/1, 2013 at 4:53

4

Solved

Hi I have below query in an SP @CrmContactId is a parameter to the SP. Select distinct A.PolicyBusinessId, A.PolicyDetailId from TPolicyBusiness A inner join TPolicyOwner B on a.PolicyDetailId=b...
Shankle asked 27/8, 2014 at 6:59

4

I'm trying to calculate League Standings from a table of Matches. +----------------------------------+ | Matches | +----------------------------------+ | id | | league_id (FK League) | | season_i...
Disincline asked 4/5, 2014 at 2:59

2

Solved

The following query is perfectly valid in pretty much every database (give or take a dual dummy table), including Oracle: select 'A' as x from dual union all select 'B' from dual order by x asc ...
Introjection asked 19/8, 2014 at 15:58

© 2022 - 2025 — McMap. All rights reserved.