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 studyCentreRecords.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLimit
FROM PSA INNER JOIN studyCentreRecords ON
PSA.patient=studyCentreRecords.patient
WHERE PSA.detectionLimit<>'<' AND PSA.totalPSA IN (SELECT PSA.totalPSA
FROM PSA WHERE PSA.detectionLimit='<' AND PSA.totalPSA<>.1)
UNION SELECT studyCentreRecords.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLimit
FROM PSA INNER JOIN studyCentreRecords ON
PSA.patient=studyCentreRecords.patient
WHERE PSA.detectionLimit='<' AND PSA.totalPSA<>.1 AND
PSA.totalPSA<>.05;
studyCentreRecords contains about 1500 records
PSA contains about 9000 records
Again, each selection on its own is fine.
Thank you,
Adam Louis 2 1511
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 studyCentreRecords.mrn, PSA.patient, PSA.id, PSA.date, PSA.totalPSA, PSA.detectionLimit FROM PSA INNER JOIN studyCentreRecords ON PSA.patient=studyCentreRecords.patient WHERE PSA.detectionLimit<>'<' AND PSA.totalPSA IN (SELECT PSA.totalPSA FROM PSA WHERE PSA.detectionLimit='<' AND PSA.totalPSA<>.1)
UNION SELECT studyCentreRecords.mrn, PSA.patient, PSA.id, PSA.date, PSA.totalPSA, PSA.detectionLimit FROM PSA INNER JOIN studyCentreRecords ON PSA.patient=studyCentreRecords.patient WHERE PSA.detectionLimit='<' AND PSA.totalPSA<>.1 AND PSA.totalPSA<>.05;
studyCentreRecords 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?
> > The query in question:
SELECT studyCentreRecords.mrn, PSA.patient, PSA.id, PSA.date, PSA.totalPSA, PSA.detectionLimit FROM PSA INNER JOIN studyCentreRecords ON PSA.patient=studyCentreRecords.patient WHERE PSA.detectionLimit<>'<' AND PSA.totalPSA IN (SELECT PSA.totalPSA FROM PSA WHERE PSA.detectionLimit='<' AND PSA.totalPSA<>.1)
UNION SELECT studyCentreRecords.mrn, PSA.patient, PSA.id, PSA.date, PSA.totalPSA, PSA.detectionLimit FROM PSA INNER JOIN studyCentreRecords ON PSA.patient=studyCentreRecords.patient WHERE PSA.detectionLimit='<' 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 studyCentreRecords.mrn, PSA.patient, PSA.id, PSA.date,
PSA.totalPSA, PSA.detectionLimit
FROM PSA INNER JOIN studyCentreRecords ON
PSA.patient=studyCentreRecords.patient
WHERE (PSA.detectionLimit<>'<' AND PSA.totalPSA IN (SELECT
PSA.totalPSA
FROM PSA WHERE PSA.detectionLimit='<' AND PSA.totalPSA<>.1))
OR (PSA.detectionLimit='<' AND PSA.totalPSA<>.1 AND
PSA.totalPSA<>.05); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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 ...
|
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...
|
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...
|
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...
|
by: Sean Dolan |
last post by:
typedef struct ntt {
int type;
union {
int i;
char* s;
};
}nt;
nt n;
n.i = 0;
|
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...
|
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...
|
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...
|
by: Peter Olcott |
last post by:
Why can a union have a member with a copy constructor?
|
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |