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 split quantities in separate columns and lines

Details These are my tables and data: create table orders ( id int not null, item varchar(10), quantity int ); insert into orders (id, item, quantity) values (1, 'Item 1', 10); create table orders_picked ( id int not null, orderId…
user19768148
1
vote
2 answers

SQL (Snowflake) - Create duplicate Records changing only a single Field after duplication

I have a table that looks like below: ID DATE_OPENED DATE_CLOSED STATUS TREATMENT 1 2022-12-05 2022-12-05 Notification Control 2 2022-11-24 2022-11-24V Viewed Control 3 2022-12-11 2022-12-11 Subjecting Control I want to duplicate…
1
vote
3 answers

Can I replace Union all with any kind on joins?

I have the below query for negative testing, But I want to replace the union all if possible. select A.* from A join B on A.COL1=B.COL1 where B.COL3 is null union all select A.* from A join B on A.COL2=B.COL4 where B.COL5 is null; Need to get…
Tanmaya
  • 15
  • 3
1
vote
1 answer

I'd like to have a bigquery query code to join and calculate 2 tables

I have 2 tables in Bigquery and I'd like to merge/join them and doing some calculation. Here are the tables : Table…
Herman K
  • 23
  • 3
1
vote
0 answers

Shouldn't this statement end with an error?

Consider the SELECT statement below: SELECT 1, 'A' UNION ALL SELECT 2, 'B' UNION ALL SELECT 3, 'C'; The result is obvious: 1 'A' 2 'B' 3 'C' I tried to store it as a separate table: CREATE TABLE tmp AS SELECT 1, 'A' UNION ALL …
Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
1
vote
1 answer

Generate a sequence of records from a base record

Is there a way to expand table 1 into table 2? It is to output each integer between start_no and end_no as a seq_no field, and take the other fields of the original table to form a new table (table 2). Table 1: date source market channel_no…
Polly
  • 603
  • 3
  • 13
1
vote
3 answers

If rows exist in table then return value from table ELSE return a default value. - MySQL

I have to write a query which will return the latest timestamp column's value from a table if rows exist. If there is no row(s) in table then it return the default value. I have write the following query in MS-SQL which is working fine for me. IF…
Lily
  • 605
  • 3
  • 15
  • 31
1
vote
1 answer

Get a multiple UNION ALL query faster

I have an issue of performance with a query with multiple UNION ALL statements. I need to add (row by row) data from different tables into the same columns. The query need to be used to create a view in MySQL, so, here an example: CREATE OR REPLACE …
AdN
  • 161
  • 1
  • 10
1
vote
1 answer

Why does Postgres choose different data solely based on columns selected?

I'm running two different queries with two unions each inside a subquery: So the structure is: SELECT * FROM (subquery_1 UNION SELECT subquery_2) Now, if I perform the query on the left, I get this result: However, the query on the right returns…
Mohammad Ayoub
  • 379
  • 2
  • 9
1
vote
2 answers

How get a Value even if result is not found in the DB mysql

I need to find the right query to get a value even if the data not exist in the db. I have my table named "prova": it en de data data riga row linie parola If I query: SELECT en,de FROM `prova` WHERE `it` IN ("data","riga"); The…
1
vote
1 answer

MySQL Where Clause with Union All getting wrong results

I will preface this by saying I am still very much learning MySQL, and I am absolutely at that stage where I know just enough to be dangerous. I have a database with data for scorekeeping for a sports league. We record wins/losses as either 1 or…
1
vote
1 answer

Mysql: How to Query 1 table with 2 different conditions and display result in separate columns

I have 1 table named ItemDelivery. I wanted to get the count of items that has DeliveryDate and the items that has been receivedDate per month. Some items deliveryDate month have different receiveDate month such as items scheduled for delivery on…
Kyushus
  • 13
  • 3
1
vote
1 answer

Ambiguious column refernce in Union All

I am receiving an error message with my union all indicating that member_key is ambiguous. Adding an alias does not seem to resolve this. Any suggestions? proc sql; Select distinct member_key into: member_ky_list separated by "," From( select…
kim
  • 11
  • 1
1
vote
0 answers

ODBC: ERROR Unknown column '' in 'field list' mysql connection using several UNION

I´m having some troubles connecting an Excel sheet with a view through the ODBC. The structure of the view is more or less this: CREATE OR REPLACE ALGORITHM = UNDEFINED DEFINER = usr SQL SECURITY DEFINER VIEW my_view AS SELECT DISTINCT…
AdN
  • 161
  • 1
  • 10
1
vote
1 answer

i've to union two different tables sym33 and sym and then check the difference of max svcdate and min svcdate which should be greater then 90 days

create temporary table sand_scipher_ds_db.public.Rf as ( select PATIENTID, max(SVCDATE)-min(SVCDATE) as days from symphony_hvh_db.sym33.dx union all select PATIENTID, max(SVCDATE)-min(SVCDATE) as days from symphony_hvh_db.sym.dx group by…