union-all

combining resultset obtained by select statements to create a view

谁说胖子不能爱 提交于 2019-12-12 00:29:19
问题 I have 4 Select statements for 4 different tables each Select query gives latest record meeting specified condition for ex: Select TOP 1 * from table where column_name = 'something' order by col1 DESC; Now I have to combine result set of all 4 queries and create a view from combined result set. 回答1: Some DB's don't let you provide an "order by" clause inside on of the unioned queries. If you're ordering by col1 desc, it's possible that it's some type of column you can apply min() or max() to.

Does NHibernate HQL support the UNION ALL keyword?

旧巷老猫 提交于 2019-12-11 07:37:46
问题 After extensive googling, I still can't find a definitive answer to this question. Some old articles/blog posts I've seen say not at all. Some say yes if the underling database supports it. Which is it? I asked on the nhusers group with no answer so far. Any help would be appreciated. 回答1: NHibernate does not support union. There is always one type in a result. What you can do is a query to a base class or interface. NHibernate will perform a union to get all the values from all tables where

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

喜你入骨 提交于 2019-12-11 06:28:05
问题 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', 'test', 'text', 'great text' from dual union all select 11111, 'one text', 12345, 'new text', NULL, 'some text', 'nice text', 'test', 'text', 'great text' from dual) tt; When I change the value test to text this code produces the error 00918. 00000 - "column

I have a large query, how do I debug this?

£可爱£侵袭症+ 提交于 2019-12-11 04:32:48
问题 So, I get this error message: EDT ERROR: syntax error at or near "union" at character 436 The query in question is a large query that consists of 12 smaller queries all connected together with UNION ALL, and each small query has two inner join statements. So, something like: SELECT table.someid as id ,table.lastname as name ,table2.groupname as groupname , 'Leads ' as Type from table inner join table3 on table3.specificid = table.someid INNER JOIN table2 on table3.specificid=table2.groupid

Does table1 UNION ALL table2 guarantee output order table1, table2?

匆匆过客 提交于 2019-12-11 00:27:50
问题 SELECT a FROM b UNION ALL SELECT a FROM c UNION ALL SELECT a FROM d Does UNION ALL guarantee to print out records from tables b, c, d in that order? I.e., no records from c before any from b. This question is not for a specific DBMS. 回答1: No order by, no order guarantee whatsoever - that's for every database. And for standard SQL, an ORDER BY is applied to the results from all the unioned queries. 回答2: To be sure in order use Select 1 as TableNo,* from a union all select 2 as TableNo,* from b

Teradata string truncated after UNION ALL

蹲街弑〆低调 提交于 2019-12-10 20:48:33
问题 I have a query with a UNION clause. One of the field is a plain hardcoded string. The string in the statement after UNION gets truncated to match the string length of the field before the UNION. Sounds confusing? Here's an example. SELECT 'abc' as xxx FROM tbl1 UNION ALL select 'defghi' as xxx FROM tbl2; For the above query, I would expect the output to be abc defghi However, the output is abc def Any thoughts? EDIT : The workaround, I am aware of currently is to have the SELECT statement

Why would I want .union over .unionAll in Spark for SchemaRDDs?

心不动则不痛 提交于 2019-12-08 15:07:15
问题 I'm trying to wrap my head around these two functions in the Spark SQL documentation– def union(other: RDD[Row]): RDD[Row] Return the union of this RDD and another one. def unionAll(otherPlan: SchemaRDD): SchemaRDD Combines the tuples of two RDDs with the same schema, keeping duplicates. This is not the standard behavior of UNION vs UNION ALL, as documented in this SO question. My code here, borrowing from the Spark SQL documentation, has the two functions returning the same results. scala>

Query very slow. The issue is “ read by other session” due to union ALL

非 Y 不嫁゛ 提交于 2019-12-08 11:33:24
问题 I have below query. the below query has union all twice. Due to this ,query is waiting for the same resource and wait time is too high. Below is the output of sql trace. Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 1 0.00 0.00 Disk file operations I/O 1047 0.00 0.15 db file sequential read 167048 0.64 1584.33 db file parallel read 216 0.05 1.37

How to use union all with manual value (not from another tabel)?

扶醉桌前 提交于 2019-12-07 04:37:49
问题 I want to use union all with manual value, not from another table. And the values are: |cSatuan1|cSatuan2|nkonversi| ============================= | LTR | PCS | 1 | | PCS | LTR | 1 | I've made the query with my own way, but it gets error. here is the query: SELECT csatuan2, csatuan1, nkonversi FROM ms_metriks union all select 'LTR','PCS','1','PCS','LTR','1' Can you tell me what's wrong with my query, and what is the right query? 回答1: Try this: SELECT csatuan2,csatuan1,nkonversi FROM ms

Let Oracle transform OR-connected predicates into UNION ALL operations

拈花ヽ惹草 提交于 2019-12-06 20:07:27
问题 UNION and UNION ALL queries can outperform equivalent queries using OR -connected predicates under certain circumstances. To my knowledge, this is partially because UNION subselects can be executed in parallel and they can thus have their own "sub-plan" specific to each part of the OR -connected predicate, which is probably far more optimal due to simpler applicable query transformations. But writing OR -connected predicates is usually much more readable and concise, even if subquery