473,657 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A problem with UNION

Hi, I'm running a query unifying two relatively simple selections.
The problem is that each selection, on its own, completes
instantaneously , but, unified, the processing takes upwards of 30
seconds. Maybe I just don't understand correctly how a union is
processed, but if anyone can explain this (and, preferably, offer a
solution or alternative), I would appreciate it.

The query in question:
SELECT studyCentreReco rds.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLi mit
FROM PSA INNER JOIN studyCentreReco rds ON
PSA.patient=stu dyCentreRecords .patient
WHERE PSA.detectionLi mit<>'<' AND PSA.totalPSA IN (SELECT PSA.totalPSA
FROM PSA WHERE PSA.detectionLi mit='<' AND PSA.totalPSA<>. 1)

UNION SELECT studyCentreReco rds.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLi mit
FROM PSA INNER JOIN studyCentreReco rds ON
PSA.patient=stu dyCentreRecords .patient
WHERE PSA.detectionLi mit='<' AND PSA.totalPSA<>. 1 AND
PSA.totalPSA<>. 05;

studyCentreReco rds contains about 1500 records
PSA contains about 9000 records

Again, each selection on its own is fine.

Thank you,

Adam Louis
Nov 12 '05 #1
2 1526
Adam Louis wrote:
Hi, I'm running a query unifying two relatively simple selections.
The problem is that each selection, on its own, completes
instantaneously , but, unified, the processing takes upwards of 30
seconds. Maybe I just don't understand correctly how a union is
processed, but if anyone can explain this (and, preferably, offer a
solution or alternative), I would appreciate it.

The query in question:
SELECT studyCentreReco rds.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLi mit
FROM PSA INNER JOIN studyCentreReco rds ON
PSA.patient=stu dyCentreRecords .patient
WHERE PSA.detectionLi mit<>'<' AND PSA.totalPSA IN (SELECT PSA.totalPSA
FROM PSA WHERE PSA.detectionLi mit='<' AND PSA.totalPSA<>. 1)

UNION SELECT studyCentreReco rds.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLi mit
FROM PSA INNER JOIN studyCentreReco rds ON
PSA.patient=stu dyCentreRecords .patient
WHERE PSA.detectionLi mit='<' AND PSA.totalPSA<>. 1 AND
PSA.totalPSA<>. 05;

studyCentreReco rds contains about 1500 records
PSA contains about 9000 records

Again, each selection on its own is fine.

Thank you,

Adam Louis

By default, a union will try to eliminate duplicate entries from the
list, if you know there will be no duplicates then use UNION ALL.
--
But why is the Rum gone?
Nov 12 '05 #2
> > The query in question:


SELECT studyCentreReco rds.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLi mit
FROM PSA INNER JOIN studyCentreReco rds ON
PSA.patient=stu dyCentreRecords .patient
WHERE PSA.detectionLi mit<>'<' AND PSA.totalPSA IN (SELECT PSA.totalPSA
FROM PSA WHERE PSA.detectionLi mit='<' AND PSA.totalPSA<>. 1)

UNION SELECT studyCentreReco rds.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLi mit
FROM PSA INNER JOIN studyCentreReco rds ON
PSA.patient=stu dyCentreRecords .patient
WHERE PSA.detectionLi mit='<' AND PSA.totalPSA<>. 1 AND
PSA.totalPSA<>. 05;


Either I'm not reading carefully enough, or you're making this way
more complicated than it should be. Why not just OR together your
criteria?

SELECT studyCentreReco rds.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLi mit
FROM PSA INNER JOIN studyCentreReco rds ON
PSA.patient=stu dyCentreRecords .patient
WHERE (PSA.detectionL imit<>'<' AND PSA.totalPSA IN (SELECT
PSA.totalPSA
FROM PSA WHERE PSA.detectionLi mit='<' AND PSA.totalPSA<>. 1))
OR (PSA.detectionL imit='<' AND PSA.totalPSA<>. 1 AND
PSA.totalPSA<>. 05);
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2978
by: News | last post by:
Folks, I need help with this task. I have a set of data that needs to be plotted on timeline chart. Example: Unit ProcStart ProcEnd Machine U1 5/5/03 6:01 5/5/03 6:04 M1 U2 5/5/03 6:03 5/5/03 6:05 M1 U3 5/5/03 6:03 5/5/03 6:04 M2 : etc. There are about 40K units and 30 serving machines. The data is in
2
7806
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a lot of repeats and the concatenation field date always comes back as January 2003 instead of the month and date its supposed to --Fiscal Year
3
5722
by: dumbledad | last post by:
Hi All, I'm confused by how to replace a SELECT statement in a SQL statement with a specific value. The table I'm working on is a list of words (a column called "word") with an index int pointing to the sentence they come from (a column called "regret"). I also have a table of stop words (called "GenericStopWords") that contains the words I do not want to consider. That table has a single column called "word". I started off using a...
6
2873
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or suggestion for improvements or conversion to iteration would be much appreciated
73
4016
by: Sean Dolan | last post by:
typedef struct ntt { int type; union { int i; char* s; }; }nt; nt n; n.i = 0;
0
5841
by: chikas | last post by:
hallo all,I need help and any tips shall be appreciated! i want to implement a I2C API(from Beck SC12 microcontroller) in a 1 wire search C-code(use to search devices on 1 wire bus) sothat that i can use Beck SC12 microcontroller to perform a 1 wire search command. I tried to implement this I2C API in the search code but my programm this not workout because my programming power is weak 1) see communication diagram on page one under:...
5
3839
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big table, we try separate this big table into twelve tables and create a view
10
3721
by: MLH | last post by:
Gentlemen: I am having one heck of a time taking a DAO walk through the records in an SQL dynaset. I'm trying to walk a set of records returned by a UNION query. I'm attempting to filter the records to those related to vehicle #60 ( = 60 ). If I explicitly specify 60 in the SQL ==everything works fine. Take a look: 100 PString = "SELECT & " & Chr$(&H22) & Space(1) & Chr$(&H22) & " & AS Recipient " 120 PString = PString & "FROM...
7
6413
by: Peter Olcott | last post by:
Why can a union have a member with a copy constructor?
5
5601
by: sonalshastry | last post by:
Hi i want to write a cursor where in branch name should be passed into the cursor one by one, I have a bill table with following detail Client, bill_date,bill_amount, branch ... I need to fetch data for top 5 client from every branch below query gives me the data across for branch A
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.