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

Is it possible to Union two ranges? - VBA

I m try to Union two ranges using Union in VBA by i m getting the below error on line Set rngBothRanges = Union(rngControl, rngFinished). Any ideas? Code: Dim arrHeaders As Variant Dim rngControl As Range Dim rngFinished As Range Dim rngBothRanges…
Error 1004
  • 7,877
  • 3
  • 23
  • 46
1
vote
7 answers

How do I create a special case Intersect clause in SQL?

I need a set of values, only when they are available in two different select statements, so I used "intersect" (select statement 1) intersect (select statement 2) but I want all the values from one of the select statements when the other select…
Ardis thrash
  • 164
  • 9
1
vote
1 answer

Pivoting a union query

I currently have two large spend databases (one for 2018 another for 2019) and have been combining the results with UNION ALL, and then pivoting in Excel to get it in a format that I want (with the years as columns). This has been working fine, but…
Jim
  • 23
  • 3
1
vote
1 answer

Why the grouped query is sorting A to Z by default?

I've created a query to get the values from the table's columns which are not null through this query: Select * from( SELECT OEID, Chest_Pain as Head, Chest_PainComment as Detail FROM tblComplaints union SELECT OEID, SOB as…
1
vote
3 answers

MySQL JOIN / UNION DISTINCT issue

I am working on a project where users need to have permissions based on which department they are connected to. So now I am trying to do a query that will show me users that have all necessary permissions based on the users department_id (users that…
Andrew Larsen
  • 1,257
  • 10
  • 21
1
vote
1 answer

Using SQL UNION with Codeigniter/PHP in an autocomplete search query

I'm trying to develop an autocomplete function in Codeigniter, can someone let me know if there is any problem with this query? It seems reasonable to me, but I'm not getting any output... for example, if someone types in 'Ma' in the search box, i…
tim peterson
  • 23,653
  • 59
  • 177
  • 299
1
vote
4 answers

SQL Query to sum multiple count union queries

I have a statement with following structure, and I'm trying to sum all the count results. I have tried using the SUM function outside of the nested count queries combined using the same variable declaration for each of the union, but error says that…
1
vote
3 answers

Mysql - union query

I have a product table as follows where a product can have 3 different packsize and prices: id | packsize1 | price1 | packsize2 | price2 | packsize3 | price3 ------------------------------------------------------------------------------- 1 …
adam78
  • 9,668
  • 24
  • 96
  • 207
1
vote
1 answer

union integer member returns the data in union while float shows abnormality

In the below code, if I print the values of union members the unassigned member int i; outputs 515. I found out that it gives the positional weight of the whole union. Q :-But if that is declared as float i; it outputs 0.000. Any particular reason…
Abhinav Kinagi
  • 3,653
  • 2
  • 27
  • 43
1
vote
2 answers

SQL how to union selections and exclude one?

At first I want to select first 5 rows with highest raiting. SELECT e.id embed_id, e.type embed_type, e.embed, IF(ul.embed_id IS NULL,0,1) liked, (SELECT COUNT(*) FROM user_likes ula WHERE ula.embed_id = e.id) u_likes FROM…
mr.boris
  • 3,667
  • 8
  • 37
  • 70
1
vote
5 answers

How to combine data from two tables with no common fields in SQL?

I have 2 tables: one table with many rows and a second table with one row. The tables have no fields in common. Is it possible to combine them into one table with many rows? I've checked UNION, but MSDN says: The following are basic rules for…
Mohit Kumar
  • 952
  • 2
  • 7
  • 18
1
vote
2 answers

PostgreSQL: function to query across multiple databases

I have several databases on the same PostgreSQL server with the exact same tables with the same columns in it. I want to write a function that a user could use to query across all these databases at once, something like: SELECT * FROM…
Gaëtan
  • 779
  • 1
  • 8
  • 26
1
vote
0 answers

Union list of slices of strings

I came across this requirement in Go where I need to take the union of slices of strings This is for Go version 1.12.5 func Union(a, b []string) []string { m := make(map[string]bool) for _, item := range a { m[item] = true } …
Dan Lee
  • 600
  • 6
  • 10
1
vote
1 answer

Combining two SQL result to form one result set in a row with different column names

As I need to combine two SQL results forming one row in the result set. I tried to make use of union function. But results in two row in the result set with oponent_* column leaving opposer_* column completely. But it should include both the column…
Nɪsʜᴀɴᴛʜ ॐ
  • 2,756
  • 4
  • 33
  • 57
1
vote
1 answer

How to set the parameters for the sql query with the union operator while using getJdbcTemplate.query(sql,new Object[],rowmapper))?

I Have the query similar to this one : sql : select count("A"),"B","C" from schema."xxx" where "TIME"=? AND "C"='mmn' group by "B","C" union select count("A"),"B","C" from schema."xxx" where "TIME"=? AND "C"='nno'…
Htijihba
  • 11
  • 3
1 2 3
99
100