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

How to select multiple values in a bidirectional many to many relationship based on input array

How to make the select statement below handle multiple inputs (a list) at once and still return a similar resulting list as to that of a single input It's been hours, and I'm stuck - I need help writing a mysql statement to retrieve a list of ids…
gheckman
  • 13
  • 3
1
vote
1 answer

MySQL union and sum two table

I need a solution for display same day records and show SUM of each column, so far I have a query to show union records like: SELECT datetime, remarks, void, invoice, reload, redeem FROM ( SELECT datetime,…
conmen
  • 2,377
  • 18
  • 68
  • 98
1
vote
1 answer

Hive union all efficiency and best practice

I have a hive efficiency question. I have 2 massive queries that need to be filtered, joined with mapping tables, and unioned. All the joins are identical for both tables. Would it be more efficient to union them before applying the joins to the…
Timothy Elbert
  • 137
  • 1
  • 3
  • 13
1
vote
1 answer

mysql query not using indexes for union all (Rows_sent: 115 Rows_examined: 1008)

I'm trying to simply 'union all' the rows of 12 tables. All tables combined , have 115 rows. However, if I run the query below I get the following when using 'explain' as well as an entry in the mysql-slow.log when set to…
olly
  • 61
  • 8
1
vote
1 answer

Insert into with union all and nextval doesn't work with duplicate values

I want to insert 2 lines in a table within one insert into statement with Oracle SQL. This code works: insert into a_glw select tt.*, work_id_seq.nextval from (select 11111, 'one text', 12345, 'new text', NULL, 'some text', 'nice text',…
yPennylane
  • 760
  • 1
  • 9
  • 27
1
vote
2 answers

Access SQL Multiple Unions with Group BY

I'm trying to run this query: SELECT HH.`Household id` AS HH_HH_ID, HH.`Annualized Premium Amount` AS HH_Annualized_Premium, GQ.`Referal SRC Id` AS GQ_Source_ID, count(*) AS Total_HH FROM Households HH INNER JOIN GatewayQ…
Mike
  • 11
  • 3
1
vote
3 answers

Why this query is not working and says Invalid Column name

SELECT ROUND(K1,2) FROM (SELECT '5.66666' UNION ALL SELECT '5.77777' UNION ALL SELECT '5.88888' UNION ALL SELECT '5.99999' UNION ALL SELECT '6.66666' UNION ALL SELECT '7.66666' UNION ALL SELECT '8.66666' UNION…
Ankit Bajpai
  • 13,128
  • 4
  • 25
  • 40
1
vote
2 answers

union is merging results

i have a query that looks as following: (SELECT title FROM pjeducations LIMIT 5) UNION (SELECT title FROM pjeducations WHERE animal != "all" LIMIT 5) UNION (SELECT title FROM pjeducations ORDER BY price DESC LIMIT 5) Some of the results in the…
vincent
  • 205
  • 1
  • 4
  • 10
1
vote
1 answer

Using Top with Union all

In SQL Server 2014, I am using the Northwind as sample database, and Orders table. For Selecting the First row: select top 1 orderID, CustomerID,EmployeeID,OrderDate,RequiredDate from orders Output: orderID CustomerID EmployeeID OrderDate …
ahmed abdelqader
  • 3,409
  • 17
  • 36
1
vote
1 answer

SELECT TOP with multiple UNION and with ORDER BY

I want to select the latest records from the DB in SQL Server. If only one item is selected the final output is this: SELECT TOP(10) * from dbo.Eventos WHERE Tipo LIKE '%OS%' AND Distrito LIKE '%' + always added at the end: ORDER BY Data…
Dillinger
  • 341
  • 3
  • 16
1
vote
2 answers

running 2 SQL select statements

I am trying to run 2 SQL Select queries to retrieve data from 2 different tables and then echo the fields from both tables. The code I am trying doesn't seem to work, any help would be appreciated. $ModelID = $_GET['model_id']; $result =…
1
vote
3 answers

UNION Query-display results in order queries are written

example - select * from discussion where title like '%india%' UNION select * from discussion where title like '%Australia%' It shows me results in order of discussion IDs mixing both typse of results I want to display India results first then…
nishant
  • 112
  • 1
  • 3
  • 10
1
vote
2 answers

Adding column contents in a SQL UNION query

So far I have this query SELECT COUNT(f.code_id) as item_count, f.code_desc FROM foo f INNER JOIN foohistory fh ON f.history_id = fh.history_id WHERE MONTH(fh.create_dt) = 6 AND YEAR(fh.create_dr) = 2010 GROUP BY …
Andy Evans
  • 6,997
  • 18
  • 72
  • 118
1
vote
1 answer

MS Access Create Table is Truncating Memo Field

Access 2013 I have several logs that are consolidated using a UNION ALL query that is written by a macro. The resulting Query is as follows: SELECT [zData Navy FY15 AFS].[Journal Voucher ID], Count([zData Navy FY15 AFS].[Journal Voucher ID]) AS…
Schalton
  • 2,867
  • 2
  • 32
  • 44
1
vote
3 answers