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
1
vote
1 answer

SAS PROC SQL UNION ALL - minimizes column length

I have 8 tables, all containing the same order and number of columns, while one specific column named ATTRIBUTE contains different data which is of length 4 to 25. When I use PROC SQL and UNION ALL tables, the ATTRIBUTE column data length in…
Eyal Marom
  • 281
  • 4
  • 18
1
vote
2 answers

How to get different rows from two tables in SQL Server

I'm trying to build a query that can give me the different rows between two tables. Here is my code: try { string searchquery = "SELECT* FROM NewList EXCEPT SELECT* FROM Restaurants UNION All"; SqlCommand searchcom = new…
Bora
  • 39
  • 6
1
vote
2 answers

Combining 3 SELECT statements to output 1 table

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(MIN FROM job_finish))) - ((EXTRACT(HOUR FROM…
Christian Hick
  • 401
  • 3
  • 10
1
vote
1 answer

UNION ALL vs UNION for Update/Returning + Select?

I'm trying to turn a query idempotent by marking rows as updated. However, part of the query spec is to return the IDs of rows that matched the filter. I was thinking of doing something like the following: WITH prev as ( SELECT id FROM…
Felipe
  • 3,003
  • 2
  • 26
  • 44
1
vote
2 answers

MySQL UNION ALL is too slow

I have a query in MySQL from 4 tables. When I run these queries individually they run quick within 1 second. But when I combine them using UNION ALL, machine comes under heavy load and take at least 10 seconds for the same query in UNION ALL. And I…
Krishan Kumar
  • 394
  • 4
  • 13
1
vote
1 answer

FAILED: SemanticException Generate Map Join Task Error: Failed to generate new mapJoin operator by exception : Index: 0, Size: 0

I am doing a union all as following: insert overwrite table T3 select * from ( SELECT cast (c1 as decimal(6,3)) as c1, c2 FROM T1 [WHERE conditions] UNION ALL SELECT c1, c2 FROM T2 [WHERE conditions] ); c1 in T2 is…
Alan
  • 417
  • 1
  • 7
  • 22
1
vote
1 answer

What is the best way to UNION ALL BigQuery tables with different data types and different columns?

I have around 50 tables under a BigQuery project created by an ETL tool from different platforms. There is no primary key in the tables and few tables have columns over 100. Each platform has different fields and different data types and the team’s…
ABY
  • 393
  • 2
  • 11
1
vote
0 answers

creating view with union more table

I got 3 tables on my sql database PL01_PROJECT DE06_PROJECT LT01_PROJECT All tables have the same columns header and number I want to create a view where is appending all table 1by 1 so to have a vie with all data from the tables I tried the…
Matt
  • 9
  • 2
1
vote
3 answers

MSSQL Union All two queries with if statement

I have a query the following works as expected If((Select count(*) from table1 where product = 'carrot')< 5) Begin Select Top (5 - (Select count(*) from table1 where product = 'carrot')) id, product From table2 WHere id NOT IN (Select id from…
Smiles
  • 71
  • 1
  • 1
  • 5
1
vote
1 answer

SELECT * with UNION ALL in Oracle

I have a requirement wherein I intend to fetch duplicate records from Oracle DB so as to mimic scenarios wherein we have duplicate records. So, I decided on using union_all. select column1 from tbl where rowid in (select rowid from tbl where…
Soumya
  • 885
  • 3
  • 14
  • 29
1
vote
1 answer

Getting a Syntax error in FROM clause with UNION ALL query

I have a Union All query that I currently run a make table query from. I am trying to consolidate them into one thing and have the union all query also just make the table. I am learning on the fly here any have been trying the INTO method which I…
Paul
  • 11
  • 2
1
vote
1 answer

Create UNION with one or more views in MySql

I am trying to get the union of a query and a view or a view and a view. But doing this in MySql gives back an ER_PARSE_ERROR. So say I have a view called B_SAL for the state of a particular data set before a particular operation. CREATE OR…
Hakim
  • 452
  • 4
  • 15
1
vote
2 answers

MySQL Union, table priority and fake columns

I am trying to query 3 mostly unrelated tables. The relation for all three is one column (an email address field). I have created a 'union all' and pulled in email from all 3 tables and then grouped at the end to make sure there are no duplicates…
1
vote
0 answers

Get sum of each column in pyspark dataframe

I have a dataframe which consists of 3 rows and more than 20 columns(dates) +----+-----+-----+ |Cat |01/02|02/02|...... +----+-----+-----+ | a | 20 | 7 |...... | b | 30 | 12 |...... +----+---+-------+ and I want to get the sum from…
Gerasimos
  • 279
  • 2
  • 8
  • 17
1
vote
1 answer

Union all of 200 select statements failing to even execute. No error thrown. Limitation of number of select statements in union all?

Because of the limitations we have in Amazon Redhshift SQL (which is based on PostgreSQL 8.0.2). I am forced to execute the following query for some other complex query purposes: create temporary table NS AS ( select 1 as n union all select 2 union…
Rahul Yadav
  • 31
  • 1
  • 7