The set of all distinct rows from two or more result sets.

learn more… | top users | synonyms

0
votes
1answer
5 views

where clause return empty row in view mysql

i have two tables with the schema below: INCOME TABLE: INCOME_ID, INCOME_NAME, INCOME_DATE OUTCOME TABLE: OUTCOME_ID, OUTCOME_NAME, OUTCOME_DATE EXAMPLE DATA INCOME INCOME_ID | INCOME_NAME | ...
0
votes
0answers
17 views

UNION Query rendering 2 columns

I am using Access 2013 SQL. I have the following query qry structure: SELECT TOP 10 [Sub Category] AS Category_1 FROM tbl WHERE [Category]='1' GROUP BY [Sub Category] ORDER BY SUM([Value]) DESC; I ...
1
vote
1answer
27 views

Sql get results only containing all keywords

Let's say I have mysql table called SONGS, with columns: Artist | Featuredartist | Songname | Year What I need is to get Artist and Songname, only containing my keywords (and no matter how they are ...
1
vote
0answers
16 views

Modeling Multiaccounts + content interactions [closed]

I'm having trouble to model a scalable database schema with performance in mind. The requirements are wide, as such that I need a schema that supports; user can swith between multiple types of ...
1
vote
3answers
16 views

I try to use select union with order by and now i can select it but it seem like it not order by date with what i expect why?

SELECT * FROM ( SELECT sale.NAME AS "Name" ,sale.responsible AS "Responsible:data:200" ,sale.action_type AS "Action Type:data:200" ,sale.id_customer AS "Id_Customer" ...
1
vote
2answers
47 views

How to find out if rows are refenced from other tables?

I have a table named contacts (primary key id) which is referenced by a number of other tables via foreign keys. When a list of contacts is displayed in the application, I get their primary keys in an ...
1
vote
1answer
38 views

SELECT UNION from multiple tables with same schema in MySQL

I want to SELECT (combine) records from multiple tables with the same schema. This is the query that I use: SELECT visitor_name, in_time, out_time, blacklist FROM visitor_archive_2012 UNION SELECT ...
0
votes
3answers
132 views

Oracle union default sort is weird [closed]

As you know union removes duplicated rows. I thought it removes from the latter ones, but it doesn't. I found out that if there's no order by clause, Oracle sorts the merged dataset by the first ...
1
vote
1answer
46 views

(MYSQL) Select union of rows depending on row before?

I have a table in MySQL that looks like this: CREATE TABLE IF NOT EXISTS `mytable` ( `id` int(11) NOT NULL, `data` VARCHAR(255), `otherid` int(11), ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT ...
2
votes
2answers
79 views

Filtering UNION ALL result is much slower than filtering each subquery

(edit: see end for a simpler example) I'm searching in a table named "cases" (135k rows, 29 columns). Some of the rows in this table have a type of parent-child relationship (of different types), ...
0
votes
2answers
72 views

MySQL -Query with Union doesnt use index

Long story short, the following query runs immediately: SELECT COUNT(*) FROM indicators.fileso WHERE sha256 IN ( SELECT a.sha256 FROM temp.ananifilesinfo a JOIN indicators.filesi fi ON fi....
1
vote
1answer
35 views

Started using UUID's as primary key, would like to execute union of entities with BigSerial Primary Key

Some of my newer tables are now using UUID type fields as PKey and older tables are still using bigserial. I have several tables (let's call them entities) I would like to query returning the primary ...
0
votes
1answer
113 views

Combining 2 SELECT queries and printing the results in PostgreSQL

I have 2 queries which I want to use together to produce one output result to the user. The output describes to the user the journey to take to from A to B. I keep getting a syntax error when I try to ...
0
votes
2answers
32 views

MySQL Union not showing 2nd query result set

I am doing a union of 2 queries and trying to fetch data on two different columns, however the union is not fetching the value from 2nd result set. Can you please guide me on this. select * From ...
3
votes
1answer
39 views

Howto combine UNION with EXISTS?

I have a query that looks like this: SELECT PubKey, Title FROM Publication UNION SELECT NoteKey, Title, FROM Note Which works fine. My trouble start when I try to add an EXIST to it: SELECT PubKey,...
1
vote
4answers
118 views

UNION xp_cmdshell

I'm trying and failing to do something a follows select 1 union xp_cmdshell 'whoami' Is there anyway to get this work? The simpler the better i.e. one statement.
1
vote
3answers
78 views

Union Query format in mysql

I am training in MySQL. I have database called ships. My goal is => For each class, define the number of ships of this class that were sunk in battles. Result set: class, number of sunked ships. Here ...
0
votes
1answer
34 views

Combining Explain and Union

Morning all, I'm trying to quickly compare multiple queries that do similar tasks and I'm wondering if there's a quicker way of lining up the EXPLAIN outputs. To me, this example query should work: ...
0
votes
1answer
109 views

Postgres: get total number of matched records using UNION

I'm running a paginated SELECT ... UNION query, and I need to determine the number of pages that are in the resultset. For example, consider the query: (SELECT id, 'table1' AS type, COUNT(*) OVER() ...
1
vote
1answer
58 views

UNION or SELF JOIN?

I have a table to hold parent and child posts together. +------+----------------+--------------+-------------+------------+ | p_id | parent_post_id | child_status | post_status | post_title | ...
0
votes
0answers
11 views

MySQL editable reports from multiple identical tables

Let's say I have two sets of four identical tables for my sales that are generated by our apparatus. The first set represents each sales made in a region. Sales_Canada_Est, Sales_Canada_West, ...
0
votes
0answers
24 views

Is it possible to stack similar columns from a subquery and join the other unique columns in one query?

I am fairly new to the sql world and have been struggling with a query. I have two subqueries that are generating tables with two columns. The first table is part # and model_countH. The second table ...
0
votes
1answer
155 views

Better ways than rownum limits on a union all for fallback-style queries?

I have three queries that generates some "reference" statistics and should be tried in order until one returns a result. These are currently coded as three separate calls to the DB, but I want to ...
0
votes
1answer
52 views

How to make an union on 2 joined tables without affecting the sum on the column? [closed]

I have the following tables: cant: id CANT_VAL COD_VAL fk_id_chest c1 c2 18059 18.56 R12 1 100 11 18060 11 R10 2 200 22 18061 15 ...
0
votes
1answer
25 views

How can I group two joined tables

How can I group (by) two joined tables (in an Oracle database) like this: cant: id CANT_VAL COD_VAL fk_id_chest 18059 18.56 R12 1 18060 11 R10 2 18061 15 ...
1
vote
1answer
51 views

Syntax error in UNION ALL [closed]

I have syntax error in UNION ALL line 8.. what is the mistake? I'm using mariadb, (Innodb) SELECT 'Süre Bitiş Tarihi','Tc Kimlik No', 'Kullanıcı Soyadı, Adı','E-posta', 'Telefon','Diğer Telefon','...
2
votes
1answer
990 views

COLLATION and UNION ALL

I have the following queries: SELECT * FROM OPENQUERY([SERVERA], 'SELECT ''SERVERA'',[PhoneNum] ,[PhoneExt] ,COUNT(2) as CNT FROM [DB].[dbo].[ResourcePhone] WHERE PhoneNum like ''+...
2
votes
2answers
119 views

Union tables by mask in PostgreSQL [closed]

In database I have many tables like with names: "t_2015_09_01_z15" "t_2015_09_02_z15" "t_2015_09_03_z15" "t_2015_09_04_z15" "t_2015_09_05_z15" ... "t_2015_10_01_z15" "t_2015_10_02_z15" "...
2
votes
1answer
79 views

SQLite WITH + UNION issue

my UNION queries cannot work when tables created by WITH are used, is this a SQLite limitation? for example - This works: with T_one as ( select * from T ), T_two as ( select * from T ) ...
3
votes
3answers
176 views

Primary key in resulting relation from union operation in relational algebra

I have a question regarding the resulting table/relation from a union operation in relational algebra. Does the resulting relation not have a primary key? Or does it return a table with a hidden ...
0
votes
0answers
57 views

Merge two data tables with different time preferably in access

I appreciate if I could help on this issue. I am relatively beginner to database designs. I have two tables (see link below) which I would like to combine: Tbl_1: Date, Product, Sold Tbl_2: Date, ...
-1
votes
1answer
221 views

Is UNION faster than UNION ALL with DISTINCT?

UNION can eliminate "Distinct" use to optimize the query? Like below, NO distinct is needed if the UNION is used to return distinct set. Sample data declare @T1 Table ( ObjId1 int , Name varchar(100)...
0
votes
1answer
40 views

UNION query question

My query is: SELECT BRAND,BRAND_GROUP, SUB_BRAND ,SUM(INCOME) AS TOTAL_INCOME FROM "tema".MMT WHERE BRAND_GROUP IS NULL AND SUB_BRAND IS NULL GROUP BY BRAND,BRAND_GROUP,SUB_BRAND UNION SELECT BRAND,...
0
votes
1answer
176 views

Convert UNION query to JOIN. Is it actually needed for high performance?

I have the following table structure in MySql. To get the list of roles for a particular user, I use the following union Query, SELECT r.ID, r.ROLE_NAME, r.TENANT_DOMAIN, r.PROVIDER_ID FROM `...
-4
votes
1answer
55 views

How does Oracle handle types in this UNION query? [closed]

SELECT 1 FROM DUAL UNION SELECT '2' FROM DUAL; what does this give? knowing dual is default table and is a single row table. update: I fixed it with SELECT 1 FROM DUAL UNION SELECT CAST( '2' ...
7
votes
2answers
122 views

Most efficient way to generate a diff

I have a table in SQL server that looks like this: Id |Version |Name |date |fieldA |fieldB ..|fieldZ 1 |1 |Foo |20120101|23 | ..|25334123 2 |2 |Foo ...
0
votes
2answers
106 views

How many passes of a table are done with UNION ALL? [closed]

I am trying to run a single query that will make a single pass through a table, and was wondering if by using UNION ALL to make counts of total row unioned with counts of unique rows so I would be ...
2
votes
1answer
113 views

Selecting max(date) from union query

I am having a bit of trouble getting accurate results from a query that looks to me as if it should work. RDBMS is MySQL. I am trying to get the max last login date from a union select on three ...
0
votes
1answer
302 views

Does PostgreSQL benefit from more cores or faster cores for READ heavy applications? [closed]

I have been trying to figure out how to go about configuration of a PostgreSQL instance that will have 64GB ram (which is far larger than the database) and if I should opt for more cores or faster ...
1
vote
1answer
37 views

To find out the sum total of GRNQty and GRNValue of particular item from column 1

Query 1 # SELECT spi.Item,spi.ItemName,supdd.PackageID,spi.Specifics,iteb.brandname,supdd.Qty AS GRNQty,supdd.GP AS UnitPrice,(supdd.Qty * Supdd.GP) AS GRNValue FROM suppdeldetail AS supdd ...
3
votes
1answer
402 views

How to union four different tables

I have two tables whereby both of them use sub queries. These two tables are combined by using UNION ALL. I have two other tables that only uses a WHERE clause and both of these are combined using ...
0
votes
1answer
380 views

Optimizing key lookup in subquery with UNION ALL

I am trying to optimize following query (little bit more complex actually, but this is important part): SELECT Id, StatusDate, [...Lot Of Columns...] FROM ( ( SELECT Id, StatusDate, [...Lot ...
1
vote
0answers
199 views

How to improve performance when joining against coalesce

In an effort to remove a caching layer from our application, I'm building a number of views to encapsulate the different ways a user can have access to a piece of content - one per "rule" of access. ...
1
vote
1answer
76 views

MySQL Summary with Union

The following query does what I want, but I need to extend it, but i'm just not enough of an SQL expert to figure out what I'm doing wrong. SELECT sd.StockNumber AS StkNm, sd.Description As Descr, ...
1
vote
2answers
437 views

Combine results of two queries, where the second relies on the first

I have one query which is returning name(text), total, created_at And another query which is returning the same thing name(text), total, created_at The second query usually is returning more ...
0
votes
1answer
1k views

Grouping UNION ALL

No matter how I try to group the record set generated by this query it just wont do it. Query works ok the problem is trying to Group by A SELECT CountryCode + + ProductNumber + + StockType AS A, ...
2
votes
2answers
177 views

Extracting Data from multiple archive tables(SQL Server)

I am developing a report in report builder 3.0 where i am extracting data from a table dbo.odcalls. now the problem is this table is archived on monthly basis on a seperate database(HN_Backup) and i ...
2
votes
2answers
69 views

How can I simplify this UNION?

Here's the case - I have the following query: SELECT DISTINCT post_id FROM ( ( SELECT DISTINCT rp.post_id, pm.meta_value AS premiere_date FROM wp_related_people AS rp JOIN ...
1
vote
3answers
2k views

Select only rows with minimum values from union table

SQL Server 2005 Here is a sampling of the data from a union of two tables (named "vProducts_All"): DBID UPC Price1 Price2 1 023614025559 689.0000 649.0000 2 ...
1
vote
1answer
243 views

Refactoring sql for tables with similar columns but different table names

I have the task of re-factoring a SQL script that performs a lot of unions from different tables. These tables have similar information, so the script queries the same columns as in each table, except ...