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

Using UNION ALL on 2 tables to obtain specific results

I am attempting to query unique results but am having issues with Query 2 as it pulls the Top 1 result of any ItemNumber instead of my desired ItemNumber from my select statement. I want to display all unique results from Query 1 & I want to display…
Brad
  • 1,450
  • 2
  • 16
  • 37
-1
votes
1 answer

How to make the name of the table shorter and how to fix the first select that has no name table

I have a very long name for a table "bigquery-public-data.new_york.nypd_mv_collisions" union all and also I don't know where to put the name for the first select.I'm trying to create one row for each vehicle type and count each of them. I want to…
d12
  • 135
  • 3
  • 11
-1
votes
1 answer

How do I merge two SELECT queries with different WHERE clauses

I'm trying to write query on two different selects with different WHERE clause and using GROUP BY. I browsed for examples but mine is different since I have multiple fields for SELECT. Here is example data: -- drop table #temp_counts; create…
SilverFish
  • 1,014
  • 6
  • 28
  • 65
-1
votes
1 answer

How to simplify multiple UNION ALL in mysql?

I have query that is becoming very huge due to multiple UNION ALL can anyone help me reduce it. There are more than 300 UNION ALL actually. SELECT keywords, COUNT(i.postId) as Posts, SUM(i.interactions) as Interactions, …
Rajnish
  • 13
  • 2
-1
votes
2 answers

how to union 2 tables but select values based on condition?

there are 2 tables - book, supply. the supply table: supply_id title author price amount 1 title1 author1 518.99 2 2 title2 author2 570.20 6 3 title3 author3 540.50 7 4 title4 author4 360.80 3 the book…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
-1
votes
4 answers

How to ROWCOUNT_BIG() value with union all

I have the following query in SQL Server. How do I get the number of rows of previous select query as following format? Sample Query select ID, Name FROM Branch UNION ALL SELECT ROWCOUNT_BIG(), '' Sample Output
Mahedee
  • 166
  • 7
-1
votes
1 answer

Alternative to union all in SQL Server

I want to write the below query without using union all. The only difference in both the queries are for 'Event' and 'Time1' columns:
-1
votes
1 answer

union all two table instead of join

I have several table which I can not join them as it gets really complicated and bigquery is not able to process it. So I am trying to union all tables and then group by. I have an issue during this process. I have two tables called t1 and t2 with…
Sana
  • 463
  • 2
  • 4
  • 22
-1
votes
2 answers

UNION ALL MYSQL is really slow

I have a query in mysql with 2 select from's. When I run these queries individually they run quick within 1 second. But when I combine them with union all, the website freeze's and it takes atleast 20 seconds for the same query to execute in union…
Naklov
  • 3
  • 2
-1
votes
1 answer

TWO RECURSIVE SELECTS UNION IN SQLITE

I want to ask question, how can I UNION these two recursive SELECTS together into the one result set. Thank you for answer WITH sub_tree (Item_id,Item_name,Item_fyz,Item_fyz_hodnotaID) AS (Select…
-1
votes
2 answers

Count data with different table

i have 2 table (device_a & device_b), i want to : union the table to and count the data for each table then group by date hour. after that i want to count data for all device then group by date hour. there is no key for join table. the result show…
hinafaya
  • 111
  • 1
  • 4
  • 16
-1
votes
2 answers

Subquery using UNION ALL in MySQL

I guess I don't understand the order in which subqueries work. When I run this SQL statement I get 1 (out of 3 that exist in the table) random 'friend id' : SELECT t1.sender_id AS Connections FROM (SELECT DISTINCT sender_id …
rollintx1
  • 1
  • 2
-1
votes
5 answers

Array binding issue with UNION ALL

I am trying to join multiple queries with UNION ALL. I tried the following code. which is giving error of Invalid parameter number: number of bound variables does not match number of tokens. $code = '1,2,3,4'; $codeArray = explode(',',…
lipon
  • 11
  • 1
  • 14
-1
votes
1 answer

Oracle: union all query 1 and query 2 want to minus some rows if query 1 have rowdata

my query as below , i want to minus some rows from query1 when query2 have rowdata , but i don't know how to do: my query: with query1 as( select wm_concat(linkman_name) name, wm_concat(phone_num) phone, t.org_id from…
cappa
  • 1
  • 2
-1
votes
1 answer

How do I use the SQL sum function to add values in different MySQL tables with the corresponding Primary Key?

I had five different tables created in MySQL containing student records. Each table basically have uniform column names. A StudentID, Subject1_Score, Subject2_Score, Subject3_Score, Total_Score. The five tables are Term1, Term2, Term3, Term4 and…
scottser
  • 13
  • 4