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

Mysql UNION ALL creates double records

I have the following tables: platforms: ------------------------------------------------------- | id | team_id| name| url |…
user2314339
  • 395
  • 1
  • 6
  • 16
2
votes
2 answers

Multiselect query returns fewer rows than expected

I am trying to select the 5 'newest' rows (The ones with the highest id) and then 10 random rows which should not be any of the 5 newest. (SELECT t1.img_app_id FROM imgs_app t1 ORDER BY t1.img_app_id DESC LIMIT 5) UNION (SELECT t2.img_app_id …
ii iml0sto1
  • 1,654
  • 19
  • 37
2
votes
2 answers

SUM of Union ALL? is it possible?

How I can SUM 2 Union all's for a field? Basically, I got 1 table working with 2 rows on it. Now I want to add 3rd row wherein I want to SUM a field in the first row and SUM a field of 2nd row and have the two SUM results appear in the third…
user9399808
2
votes
2 answers

Last row in SQL

I have a query like this select top 1* from table1 where organizationID= 79 order by D_Index desc select top 1* from table1 where organizationID= 87 order by D_Index desc select top 1* from table1 where organizationID= 19 order by D_Index…
see sharp
  • 79
  • 1
  • 1
  • 9
2
votes
1 answer

SQL UNION to SORT by two different ORDER BY clauses and remove duplicates

I've researched this for the past two days on stackoverflow and the web and still not getting my desired result. Im using ORACLE 11G. I have two SQL queries with two different ORDER BY clauses. Both must retain the correct sort order. I just want to…
Chris M
  • 143
  • 2
  • 14
2
votes
1 answer

How to split results from one field into two separate fields in SQL Server 2014

I am trying top generate a report that gives me the amount of traffic per hour, per lane, per direction. The results I'm getting so far: |TransDate |Hour |Lane| Direction| Count| --------------------------------------------- |2017-09-05 |1:00…
user1777929
  • 777
  • 1
  • 10
  • 28
2
votes
1 answer

Partitioning and Ordering in Multiple Union Statements

Good morning, I am working on combining many metrics for our dashboarding team into a single executable stored procedure they could copy into Excel and then let pivot tables do some magic. That being said, for the sake of this question I will only…
ct253704
  • 21
  • 3
2
votes
3 answers

SSIS union all vs sql server Union All

I use SQL Server 2012 and SSIS. I have two Tables in the same server and same database. I need to transfer all records of both tables into third table. I need to add some columns (Like Execution ID and some Package Parameters) to result of UNION ALL…
Ardalan Shahgholi
  • 11,967
  • 21
  • 108
  • 144
2
votes
2 answers

How to ORDER BY one query only in a UNION ALL without subquery

I'm creating a list from unrelated data using UNION ALL in order to be saved to Excel in SQL Server 2008. Only one of the SELECT statements will have an ORDER BY and that is where my issue arises with the following error message 'The multi-part…
sams
  • 439
  • 1
  • 4
  • 17
2
votes
2 answers

How can I get Oracle to use indexes when my view contains a UNION ALL?

VIEW1 IS: SELECT A, B, C FROM view2 UNION ALL SELECT A, B, C FROM view3 INNER JOIN TBL5 ON view3.CODE = TBL5.CODE Column C is indexed in the source tables, and when I execute either of the select statements individually it uses the index and…
aw crud
  • 8,791
  • 19
  • 71
  • 115
2
votes
3 answers

Oracle UNION ALL not returning full set

I have two tables that are populated with the same structure into 2 different tables: MST3_CURR and MST4_CURR. Accounts are populated into one of the two tables; each table holds accounts that are in a different 'state'. In order to generate a…
2
votes
2 answers

MYSQL: Error joining 2 select statements that include a stored function

Good Afternoon, I created a stored function to emulate the behavior of the "SHOW GRANTS FOR" command in MySQL. The script definition is as follows: CREATE FUNCTION get_grants(p_user text, p_host text, p_type text, p_obj text) RETURNS text …
2
votes
4 answers

Merge multiple columns into one column with multiple rows

In PostgreSQL, how can I merge multiple columns into one column with multiple rows? The columns are all boolean, so I want to: Filter for true values only Replace the true value (1) with the name of the column (A, B or C) I have this table: ID |…
kitsune
  • 25
  • 1
  • 4
2
votes
2 answers

SQL Order of processing

Consider I have a query like select * from A Except select * from B union all select * from B except select * from A Query is processed like select * from ( select * from A Except select * from B ) a union all ( select * from B Except…
ask_Overflow
  • 275
  • 3
  • 15
2
votes
1 answer

Oracle Convert Select Union All to Parallel Select

I don't know if it's possible or not in terms of oracle execution architecture so I just wanted to ask. I have a table that stores some schemas names (eg. sch1, sch2, sch3 ) and I am creating a union all query dynamically within a cursor using this…
Deniz
  • 191
  • 1
  • 6
  • 17