I have a problem with using a subquery in MS Access. The purpose of the sub-query is to create a list of people who have had doctor exams in the past 6 months and exclude them from the main query. This is what I came up with: - SELECT GI.generalinfoid AS GeneralInfoId, max(GI.FirstName) AS FirstName, max(GI.LastName) AS LastName, max(TI.ImagingDate) AS ImagingDate, Max(EM.embolizationDate) AS embolizationDate
-
-
FROM tblImaging AS TI RIGHT JOIN (qryGeneralInfo AS GI INNER JOIN tblEmbolizations AS EM ON GI.generalInfoID=EM.peopleID) ON TI.GeneralInfoID=GI.generalinfoid
-
-
WHERE ((GI.name) Is Not Null Or (GI.name)<>"" Or (GI.Lastname) Is Not Null Or (GI.Lastname)<>"") And (GI.generalinfoid)<>14598 And (GI.active) Like "Yes" And (GI.EMBCOUNT)>=1
-
-
-
and TI.GeneralInfoID not in (select distinct GeneralInfoID from tblImaging TI where DateDiff("m",(TI.ImagingDate),Now())<=6)
-
-
-
GROUP BY GI.generalinfoid
-
ORDER BY max(GI.LastName);
The above query does not cause an error but it does not return any data. If I take out the subquery part, it returns over a thousand rows. If I replace "not in" with "in" in the subquery it returns about 65 rows. What can I do to recover the missing 900+ rows with the "not in" subquery?
Incidentally, I tried the following solution but it errored out my Access program: - SELECT GI.generalinfoid AS GeneralInfoId, max(GI.FirstName) AS FirstName, max(GI.LastName) AS LastName, max(TI.ImagingDate) AS ImagingDate, Max(EM.embolizationDate) AS embolizationDate
-
-
-
FROM tblImaging AS TI RIGHT JOIN (qryGeneralInfo AS GI INNER JOIN tblEmbolizations AS EM ON GI.generalInfoID=EM.peopleID) ON TI.GeneralInfoID=GI.generalinfoid
-
-
-
WHERE NOT EXISTS
-
-
(select distinct GeneralInfoID from tblImaging TI where TI.generalInfoID = GI.GeneralInfoID AND DateDiff("m",(TI.ImagingDate),Now())<=6)
-
-
AND
-
-
((GI.name) Is Not Null Or (GI.name)<>"" Or (GI.Lastname) Is Not Null Or (GI.Lastname)<>"") And (GI.active) Like "Yes" And (GI.EMBCOUNT)>=1
-
-
-
GROUP BY GI.generalinfoid
-
ORDER BY max(GI.LastName);
Anyways, any help would be greatly appreciated. Thanks in advance.
13 3803
How many rows does the subquery return? - select distinct GeneralInfoID from tblImaging TI where DateDiff("m",(TI.ImagingDate),Now())<=6
The subquery returns 65 Rows
Try using a different alias for the subquery. Right now the main query's TI alias overlaps with the subquery's TI, that may be the problem. Or leave off the subquery's alias altogether.
Tried this...Gave me the same result of no rows - SELECT GI.generalinfoid AS GeneralInfoId, max(GI.FirstName) AS FirstName, max(GI.LastName) AS LastName, max(TI.ImagingDate) AS ImagingDate, Max(EM.embolizationDate) AS embolizationDate
-
-
FROM tblImaging AS TI RIGHT JOIN (qryGeneralInfo AS GI INNER JOIN tblEmbolizations AS EM ON GI.generalInfoID=EM.peopleID) ON TI.GeneralInfoID=GI.generalinfoid
-
-
WHERE ((GI.name) Is Not Null Or (GI.name)<>"" Or (GI.Lastname) Is Not Null Or (GI.Lastname)<>"") And (GI.generalinfoid)<>14598 And (GI.active) Like "Yes" And (GI.EMBCOUNT)>=1
-
-
-
and TI.GeneralInfoID not in (select distinct GeneralInfoID from tblImaging tbm where DateDiff("m",(tbm.ImagingDate),Now())<=6)
-
-
-
GROUP BY GI.generalinfoid
-
ORDER BY max(GI.LastName);
NeoPa 32,556
Expert Mod 16PB
It seems to me that your original line 8 - and TI.GeneralInfoID not in (select distinct GeneralInfoID from tblImaging TI where DateDiff("m",(TI.ImagingDate),Now())<=6)
is equivalent to : - AND DateAdd('m',6,TI.ImagingDate)>=Date()
Would that not be a little more straightforward?
It seems to me that your original line 8 - and TI.GeneralInfoID not in (select distinct GeneralInfoID from tblImaging TI where DateDiff("m",(TI.ImagingDate),Now())<=6)
is equivalent to : - AND DateAdd('m',6,TI.ImagingDate)>=Date()
Would that not be a little more straightforward?
Good catch, totally missed that. I should concern myself more with what the query is trying to achieve.
But a not on aliases. If you use an alias, then every field from that table has to be prefixed with alias.
NeoPa 32,556
Expert Mod 16PB
But a not on aliases. If you use an alias, then every field from that table has to be prefixed with alias.
Hi PW.
What did you mean by your second paragraph?
Hi PW.
What did you mean by your second paragraph?
I don't know...
lol, What I meant was:
On a side note. If you use an alias, then every field from that table has to be prefixed with alias.
NeoPa 32,556
Expert Mod 16PB
A bit like the following? : - SELECT PW.Field1,PW.Field2
-
FROM PeskyWabbit AS PW
Seriously, I didn't find that to be necessarily true in my testing. - SELECT PW.Field1,Field2
-
FROM PeskyWabbit AS PW
worked fine for me (Strangely, I didn't use these exact terms :D).
A bit like the following? : - SELECT PW.Field1,PW.Field2
-
FROM PeskyWabbit AS PW
Yeah, he did that in his main query but not in his subquery.
NeoPa 32,556
Expert Mod 16PB
Sorry PW, I retro edited my last post to avoid accusations of post whoring :embarassed:
Seriously, I didn't find that to be necessarily true in my testing. - SELECT PW.Field1,Field2
-
FROM PeskyWabbit AS PW
worked fine for me (Strangely, I didn't use these exact terms :D).
Hmm, perhaps not. I don't know where I got the idea from.
NeoPa 32,556
Expert Mod 16PB
I would guess from one of those clever self-linking sub-queries you're so good at ;) There it would certainly make sense.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marcin Dobrucki |
last post by:
I've been having some problems with a parse error that I can't figure
out (PHP 4.3.11 on Solaris9). Sample code:
<?php
// getting strange parse errors on this
class A {
var $value;
function...
|
by: gary |
last post by:
Hi,
We all know the below codes are dangerous:
{
int *p = new int;
delete p;
delete p;
}
And we also know the compilers do not delete p if p==NULL.
So why compilers do not "p = NULL"...
|
by: TCB |
last post by:
Hi,
There are a couple of things that are bothering me, any help on these is
greatly appreciated. This is using ASP.NET 2.0
1. I am sending email in my web app, using a simple form here is the...
|
by: Chad |
last post by:
Should links automatically appear in the "visited" color as defined by the
user's IE settings without having to add any special coding?
I have a situation where the link was not changing color...
|
by: Branco Medeiros |
last post by:
Hi all,
Using SQL Server 2000, SP4.
I have a table of street names (Rua) whose ids (cod_rua) are foreign
keys into a consumer table (Consumidor). It turns out that the "Rua"
table has many...
|
by: Robbie Hatley |
last post by:
Greetings, group. I just found a weird problem in a program where
a variable declared in a {block} after a "case" keyword was being
treated as having value 0 even though its actual value should...
|
by: anyonefour |
last post by:
Hai
How we can give the <a href> tag in xml code. Is ther any other tags for giving hyperlink in xml. Please inform me.
Thanks & Regards
|
by: fran7 |
last post by:
Hi, from help in the javascript forum I found the error in some code but need help. This bit of code works perfectly, trouble is I am writing it to a javascript function so the height needs to be in...
|
by: Muzammil |
last post by:
i have problem with this operator "+" in doubly circular link list.(i
think i have problem with return type).
error is of instantiate error.(mean type dismatch) if any one can help
me please...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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,...
| |