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
3 answers

Access union all into new table

I have a saved query (MyUnion) for a union, appending monthly files (linked views): select * from RawTrade1801 union all select * from RawTrade1802 Trying to write this to a new table is proving problematic: SELECT MyUnion.* into RawTrade2 FROM…
E.D.
  • 319
  • 1
  • 5
  • 15
1
vote
1 answer

MySQL errors using UNION ALL with subqueries and variables

I have a table currency_lkp and a table associate_data The associate_data has these columns - currency, invoice_total and status (Unpaid or Paid or WaitingI) I can succesfully link the tables with the top half of this query (see MySQL fiddle) and…
paul724
  • 145
  • 3
  • 13
1
vote
2 answers

How to perform case sensitive group by in MS Access

In MS Access database to find the mismatch (i.e. difference) records between two tables(Employee and Employee_PROD) I am using the UNION ALL. The query is as follows: SELECT [COMPANY],[DEPT],[DOJ],[EMP_ID],[Name],[SUB_COMPANY] FROM (SELECT…
Dukhabandhu Sahoo
  • 1,394
  • 1
  • 22
  • 44
1
vote
2 answers

UNION ALL results are not sorted properly

It is necessary to make a complex selection from the table with sorting for different conditions. When I make two requests separately, then everything works, and if I combine, it outputs without sorting - by the growth of the key field of the…
Dr.Noname
  • 73
  • 10
1
vote
2 answers

How do i count this mysql UNION query

This is my query, i'm kinda still getting a hang of mysql joins. i would like to get the count of this query.... SELECT * FROM `users` WHERE id = '4' UNION SELECT * FROM `users` WHERE id IN (SELECT group_id FROM `users` WHERE id = '4') AND…
Victor Mbachu
  • 13
  • 1
  • 5
1
vote
5 answers

SSMS SQL - ORDER BY stops working when adding UNION ALL?

I have 3 different queries with a UNION ALL between them. With one of the queries, I'm attemping to use an order by, which works when running that batch on its own, but as soon as I introduce the rest of it with the UNIONs, the ordering stops…
Smeghead
  • 185
  • 3
  • 12
1
vote
2 answers

Can I use Distinct with Union All in MySQL?

I am getting values from different tables using UNION ALL. My code is as below. SELECT DISTINCT datei, amount FROM ( SELECT datei, amount, 1 AS identification FROM income UNION ALL SELECT datee, amount, 2 AS identification FROM expense …
TarangP
  • 2,711
  • 5
  • 20
  • 41
1
vote
1 answer

Wierd Syntax Error when working with Order By clause with Union All in Toad for Sql Server 2016

I want Union of two result set of periods. First set contains periods whose payroll is closed and the second set having only one period which is active. So I do order by in the second set to derive the active period in ascending order. But I always…
Raida Adn
  • 405
  • 1
  • 6
  • 17
1
vote
1 answer

ORDER BY NEWID() AND UNION using MS SQL

I'm trying to execute following SQL query over MS. SQL, objective is to select random records from both queries and union them together but its generating the error at ORDER BY NEWID() select 2 random questions when subject_id=1 union select 3…
QSS
  • 41
  • 1
  • 8
1
vote
1 answer

Oracle SQL - using 'union all' within a 'with as'-statement and many tables

In my new business job I encountered a database structure where tables are numbered like table_1, table_2, table_3, ... (up to 20) All of that tables have the same structure like Id, Name, Surname. Now I got a request to show the Id's where…
Craiten
  • 109
  • 1
  • 2
  • 12
1
vote
0 answers

Issue in Spark not able to read S3 subfolders of a hive table

I have 3 non-partitioned tables in Hive. drop table default.test1; CREATE EXTERNAL TABLE `default.test1`( `c1` string, …
Sri
  • 623
  • 3
  • 9
  • 22
1
vote
3 answers

Deciphering SQL query

I am currently reviewing a query without access to the databases on which the query is performed. (It's not ideal but that's what I am tasked with). I am not a SQL expert and trying to identify what the below code does as I cannot run the query. It…
Run3Pal
  • 13
  • 2
1
vote
1 answer

Perform a union only if table exists in database

I have a composite query where I perform UNION between multiple table. Now My query fails when table does not exists. (Use case is that a table on which select query is perform is created on 5th of every month so my query fails till 5th of the…
Rajan
  • 2,427
  • 10
  • 51
  • 111
1
vote
2 answers

Union of two Spark dataframes with different columns

I am trying to union two Spark dataframes with different set of columns. For this purpose, I referred to following link :- How to perform union on two DataFrames with different amounts of columns in spark? My code is as follows - val cols1 =…
Ishan
  • 996
  • 3
  • 13
  • 34
1
vote
2 answers

Abort subsequent UNION ALL commands if match found [H2]

How do I adapt the query below so that it doesn't perform unnecessary UNION ALL unless the SELECT statement above it doesn't find a match? SELECT LATITUDE, LONGITUDE FROM coordinates WHERE address = ? AND community = ? UNION ALL SELECT LATITUDE,…
IanSky
  • 31
  • 6