Skip to main content

Questions tagged [union]

Combines two or more query results. UNION removes duplicates; UNION ALL retains all rows.

0 votes
0 answers
50 views

I have an SQL query with a subquery, like this: SELECT field1, json_agg(json_object('key', field2, 'total', "total") order by field2) as "my data" FROM ( SELECT field1, ...
Sergey Zaykov's user avatar
3 votes
2 answers
185 views

I have a table with speeds at different time intervals: CREATE TABLE speeds ( result_id uuid NULL, t10 float4 NULL, t30 float4 NULL, t60 float4 NULL, t120 float4 NULL); And some ...
Noah Rivers's user avatar
17 votes
1 answer
2k views

I have the following query and expect that as a result I will have a list of IDs without duplicates. But sometimes it produces duplicates (1-2 on 4 million rows). Why can it happen? I run it with the ...
Novitskiy Denis's user avatar
2 votes
1 answer
158 views

I have two different queries that I need to UNION together and then aggregate each rate type group together into a final table. For each rate group (Rate_001mo, Rate_003mo, etc.) SELECT EffectiveDate,...
Daylon Hunt's user avatar
8 votes
1 answer
294 views

I am observing significant performance impact of select lists in sorted UNION queries. The general form of UNION queries I am working with is: SELECT * FROM ( SELECT <select_list> FROM <...
jajanken's user avatar
0 votes
2 answers
121 views

i am stuck with an exercise. using WideWorldImporters DataBase I need to show my results this way: but no matter what I do in order to get to this exact solution I can't, because the month column is ...
Lipaz Hagai's user avatar
0 votes
2 answers
117 views

I’m currently debating with a colleague whether the following (pseudo) code is vulnerable to SQL injection (SQL Server): database.BeginTransaction(); String userId = dto.UserId; String firstQuery = &...
D.Dave's user avatar
  • 1
0 votes
0 answers
287 views

In the following example variables in single quotes '' are arguments passed to the PostgreSQL query. If 'tag_args' is an empty array, the first row of result table is a row of three nulls and I use ...
jvkloc's user avatar
  • 133
1 vote
2 answers
2k views

I have two relatively complex SQL queries which I join using a UNION ALL. Each individual query is fast and returns instantly. The problem is that once joined together they perform terribly bad, and ...
laurent's user avatar
  • 201
2 votes
1 answer
286 views

I saw in that somebody exchange below code: SELECT PK1 , PK2 , PK3 , PK4 , C , B , SUM(NUMERIC_1) , SUM(NUMERIC_2) , MAX(NUMERIC_3) , SUM(NUMERIC_4) FROM ...
adam.g's user avatar
  • 487
0 votes
0 answers
234 views

These tests were ran on PostgreSQL v15.2 I'm using UNION ALL to combine the results of various queries. The separate queries perform well: explain analyze (with params as (select foo, data->>'...
sjoene's user avatar
  • 1
0 votes
1 answer
111 views

PostgreSQL seems to fail recognising the sorting is performed by constant and and each constant unambiguously defines corresponding row source, and as a result I observe it computes all row sources ...
Andrey B. Panfilov's user avatar
0 votes
1 answer
112 views

I have a huge table like following: CREATE TABLE public.huge_table ( sampl_day date NOT NULL, tick_time timestamp(6) with time zone NOT NULL, crit_feat integer NOT NULL, --- --- ...
Leon's user avatar
  • 413
1 vote
3 answers
5k views

The query below seems simple and straightforward, yet it produces unexpected results. CREATE TABLE #NUMBERS ( N BIGINT ); INSERT INTO #NUMBERS VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9) ;...
SlowMagic's user avatar
  • 151
6 votes
1 answer
725 views

I use Postgres 13 and have a table defined with the following DDL: CREATE TABLE item_codes ( code bytea NOT NULL, item_id bytea NOT NULL, time ...
Vitalii Vitrenko's user avatar

15 30 50 per page
1
2 3 4 5
16