Questions tagged [union]

Use this tag only for questions about UNION, a keyword of the SQL language for combining the results of multiple SQL queries. Use [union-all] for the UNION-ALL keyword. Use the tag [unions] for unions in C, C++, and similar languages.

UNION is a keyword of SQL for combining the results of multiple SQL queries. The results are combined and duplicate rows are eliminated (similar to DISTINCT). If UNION ALL is used, the rows are combined but duplicates are not removed.

Use the tag for unions in C, C++, and similar languages. Use for the UNION-ALL keyword.

Reference

5266 questions
1
vote
1 answer

Redshift: I try to use Union but it returns 3 columns instead of 4. What can I do?

I have to find the streams that took place in a specific country and specific dates (overall_streams) and then for the same country and dates, I have to find the streams for a specific product. In other words, I am trying to compare how the product…
Nel L
  • 135
  • 2
  • 10
1
vote
3 answers

Union with nested list/multiple for loops

I have a dictionary like so: myDict = {'items': [{'names': [{'longName1', 'shortName1'}, {'shortName2', 'longName2'}]}, {'names': [{'longName3', 'shortName3'}, {'shortName4',…
ILostMySpoon
  • 2,399
  • 2
  • 19
  • 25
1
vote
3 answers

Union of a list of rectangles

I have a list of AWT rectangles. I want to compute the union of the rectangles in an elegant way. Here is my code which works but does not look very elegant. Rectangle union(List rects) { if (rects.isEmpty()) { return new…
Daniel
  • 13
  • 1
  • 3
1
vote
2 answers

Create 3 lists from sample that are mutually exclusive and collectively exhaustive

let's say I have a master array of 365 dates in YYYYMMDD format. I want to create, for the sake of this example, 3 different lists that are unique, but also use up the entirety of the 365 dates. For an overall example, let's take the year of 2017. I…
WX_M
  • 458
  • 4
  • 20
1
vote
1 answer

(TypeScript) argument gets its type from the union of its sibling's (all of which are fns) return types

I'm trying to create a generic function that takes in two parameters, the first of which is an array of functions. The second parameter’s type should be the union of the return types of the first parameter's elements (all of which are…
Harry Solovay
  • 483
  • 3
  • 14
1
vote
1 answer

How do I convert this query into one using joins/unions in SQL Server 2016?

My join and union skills are rudimentary at best. Could some body help me change the below query into something more efficient? CREATE TABLE [dbo].[Doc2ChaptAssignment] ( [DocID_FK] [numeric](18, 0) NOT NULL, [mChapterID_FK] [numeric](18, 0)…
Gregbert
  • 121
  • 1
  • 11
1
vote
1 answer

How can I remove the null values and make it to 10 rows in Postgresql?

I am new to Postgresql. I have a table called 'sales'. create table sales ( cust varchar(20), prod varchar(20), day integer, month integer, year integer, state char(2), quant …
Wikiz Vito
  • 43
  • 7
1
vote
1 answer

Create union type based on array of types

Is it possible to define union type like this: Union = // something... and would be used like Union<[string, number]> // would create (string | number) I know I can immediatelly define union above, but I need it for usage in…
zhuber
  • 5,364
  • 3
  • 30
  • 63
1
vote
4 answers

Convert ListBuffer of Dataframes into one single Dataframe Spark Scala

I have a ListBuffer of 30 DataFrames with the same fields and I want to 'append' them all at once. What is the best way and most efficient? var result_df_list = new ListBuffer[DataFrame]() I have seen that you can create a Sequence of DF like…
1
vote
1 answer

Microcontroller bit fields

I am learning about microcontrollers and I am having difficulty understanding how one would use a union to set individual bits on a gpio port. typedef union _BYTE { byte _byte; struct { unsigned b0:1; unsigned b1:1; …
user623879
  • 4,066
  • 9
  • 38
  • 53
1
vote
1 answer

How to select a Column from inside a Union

I am trying to select 4 Columns from temp tables I have created, I am struggling to get one of the columns to display its data. I have written the statement differently to try and get the correct data however an Union is needed in order to subtract…
KavenM
  • 7
  • 4
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
1 answer

Single grand total ROLLUP with multiple columns

I am looking to add a single grand total for salaries to my table, which is also based on a selection of multiple columns. The code I'm stuck on is below: SELECT country, state1, city, street, ID, lastname + ', ' + firstname AS 'Name', SUM(salary)…
1
vote
1 answer

Is there a way to make multiple UNION's more efficient when they all do the same joins?

I have 3 tables and I'd like to make a view that aggregates data vertically (using UNIONS) from the 3 tables. I already have a query that does what I want, but it uses a lot of repeated joins for each query, and I'm wondering if there is a way to…
Davis Mariotti
  • 574
  • 1
  • 4
  • 23
1
vote
1 answer

Nested query in sql server

Hello then the query below performs a select on a sql server database, the problem is that the total field is calculated as the total of all the tables, not of each , how can I run the account individually?Each table has a construction field and I…
user10295588