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

MySQL Union query: PASSING TEMP ClaimID field value to TEMP1 table ClaimID in one union query

CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_DupAuditCriteria_1`() BEGIN set @RowNbr=concat(date_format(curdate(),'%Y%m%d'),'0000000'); select temp.* from (SELECT c.*, concat(c.VendorID,a.VendorID) as MergeH200A,…
NVReddy
  • 52
  • 6
-1
votes
1 answer

How to get total qty and consumed qty into single results using SQL query

I am having below Tables 1. Material Unit: id | Unit_name 1 | Nos. 2 | lts 2. Material Table: id | Material_name 1 | bricks 2 | Cement 3. Grn Table: id | material_id | qty | unit 1 | 1 | 100 | 1 2 | 2 | 500 | 1 3 |…
-1
votes
1 answer

How to select if a given data exists in multiple tables and then update to table with result (only one table brings result)

Somethings like: UPDATE Table(Customers or Customers2) SET City ="A" FROM ( SELECT City FROM Customers where id=1 UNION SELECT City FROM Customers2 where id=1)
-1
votes
3 answers

mysql select multi rows equal from row 2

I have two tables: TableA TableB ID_A ID_B P1 Text P2 P3 P4 - TableB ID_B Text 1 A 2 B 3 C 4 D 5 E 6 F 7 G - TableA ID_A P1 P2 P3 P4 1 7 5 6 6 thanks…
-1
votes
1 answer

MSAccess SQL Query - Union all with multiple tables - Duplicate field

I'm trying to take the total from three queries qryBOM , qryLabour and qryLaser and have them listed on one line. I've create a qryTotals Filter and here's my code: SELECT Sum(tempTotalLabour) AS TotalLabour, Sum(tempTotalCost) AS TotalCost, …
Walshie1987
  • 443
  • 2
  • 6
  • 19
-1
votes
3 answers

Dynamic SQL + UNION ALL - repeat the same statement for all cells of a single column

I'd like to combine multiple result-sets of i (i=1,...,n) SELECT statements using UNION ALL. Example: select person_id, brand from anydatabase where brand = 'A' union all select person_id, brand from anydatabase where brand = 'B' ... I'd like to…
superdell
  • 21
  • 2
-1
votes
2 answers

joined two queries with union all returned single value only?

i have merge two queries from where its returning 3 columns (month, count, targets) by executing both queries separately it returns me 2 records which is correct. but with UNION ALL its return me only single value: My Query: select…
-1
votes
1 answer

Adding additional joins to SQL Union All

My current SQL union all statement aganst a table called Person ALTER PROCEDURE [dbo].[uspGetOrgChart] @ContactID varchar(100)='NOE1WWD' AS BEGIN --grab id of @contactid DECLARE @Test varchar(36) SELECT @Test = (SELECT ADID FROM Person c1 WHERE…
Derek
  • 41
  • 1
  • 8
-1
votes
4 answers

How to 'Union all' two tables and the result to update the second table

I'm trying to UNION ALL (fully join both tables (they have the same column names)) two tables together but update the second table with the result of the union. The code below gets the result I want but doesn't update table 2 with the result SELECT…
Sam
  • 25
  • 5
-1
votes
1 answer

UNION MySQL, Check if its bold

Hello guys i have that SQL: SELECT p.* FROM products p WHERE required_product_id IS NULL UNION ALL SELECT p.* FROM products p, orders o WHERE p.required_product_id = o.product_id AND o.user_id = 1 UNION DISTINCT SELECT p.`*` FROM products p,…
Lubomir Stankov
  • 169
  • 1
  • 3
  • 16
-1
votes
1 answer

Using UNION ALL in SQL

I added the two UNION ALL statements to get the complete data because it is in three different tables with the same column names and data types. I am getting the ORA-00907: missing right parenthesis error which i've researched and still can't figure…
-1
votes
1 answer

Prioritize Bulk Insert in a table using Union all in ssis

I have multiple archive tables storing similar kind of data in these tables but archived in the month wise format. Now, the requirement is to get all the archived data in to one table instead of multiple tables. I am doing this activity with the…
-1
votes
1 answer

Getting column ambiguously defined when I shouldn't. Why?

I have two tables that return results when I put them together using UNION ALL, like this: SELECT * FROM TABLE_A UNION ALL SELECT * FROM TABLE_A But for some reason when I add this code into a WITH clause, like below, it does not work: WITH …
Zolt
  • 2,761
  • 8
  • 43
  • 60
-1
votes
2 answers

I want to merge two tables [Tabl1] and [Tabl2] and show result by ID where [Tabl1].[names] = 'any string name'?

In my example where name like '' show all value tabl2 with tabl1 SELECT * FROM (SELECT ID, names, NULL AS address, work, note FROM Tabl1 UNION SELECT ID, name, address, NULL, NULL FROM …
Sraj Muneer
  • 27
  • 2
  • 8
-1
votes
4 answers

How to Union Uncommon Columns in SQL

What SELECT Statement should I write to get desired table from Tabel1 & 2 Table 1 - Charge Table Table 2 - Order Table Desired Table
Lokapedia
  • 105
  • 1
  • 4
  • 12