A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Select query help



 
 
Thread Tools Display Modes
  #1  
Old April 26th, 2010, 03:50 AM posted to microsoft.public.access
MikeR
external usenet poster
 
Posts: 147
Default Select query help

I have tblLog. It's fields a
Call: text
Freq: single
Mode: text
CID: text
QSL_R: text
Credited: T/F

I need the SQL to return all records where 'Credited' is false, 'QSL_R' NULL or
blank, and whose combination of 'Freq' and 'Mode' for a given 'CID' have 'Credited' =
false, but not if that record has a 'mate' whose 'CID', 'Freq/Mode', 'QSL_R' all
match, and 'Credited' is True.

I'm not sure if my description is understandable, so here is an example.

Call Freq Mode CID QSL_R Credited
1A0KK 14.210 SSB 1A0 Y True
1A0XX 14.210 SSB 1A0 Y False
1A0LY 14.310 CW 1A0 Y False
1A0KK 7.009 CW 1A0 Y True
1A0TT 3.506 TTY 1A0 False
NF4L 18.080 TTY K Y False
NF1Y 18.083 TTY K False
WA4B 7.080 TTY K Y True
K4UTE 18.125 SSB K Y False
AB4UF 14.230 SSB K Y False

These records should be in the return set.
1A0LY 14.310 CW 1A0 Y False
NF4L 18.080 TTY K Y False
K4UTE 18.125 SSB K Y False
AB4UF 14.230 SSB K Y False

Thanks,
Mike
  #2  
Old April 26th, 2010, 05:13 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Select query help

On Sun, 25 Apr 2010 22:50:01 -0400, MikeR wrote:

I have tblLog. It's fields a
Call: text
Freq: single
Mode: text
CID: text
QSL_R: text
Credited: T/F

I need the SQL to return all records where 'Credited' is false, 'QSL_R' NULL or
blank, and whose combination of 'Freq' and 'Mode' for a given 'CID' have 'Credited' =
false, but not if that record has a 'mate' whose 'CID', 'Freq/Mode', 'QSL_R' all
match, and 'Credited' is True.


A Query such as

SELECT * FROM tblLog
WHERE [Credited] = False
AND [QSL_R] IS NOT NULL
AND ([Credited] = FALSE AND NOT EXISTS (SELECT [Call] FROM tblLog AS X
WHERE X.Call = tblLog.Call
AND X.Credited = True));


should work. The NOT EXISTS clause may be slow, and could probably be replaced
by a JOIN but I'd need to mock up a table to test it.

--

John W. Vinson [MVP]
  #3  
Old April 26th, 2010, 09:32 PM posted to microsoft.public.access
MikeR
external usenet poster
 
Posts: 147
Default Select query help

John W. Vinson wrote:
On Sun, 25 Apr 2010 22:50:01 -0400, MikeR wrote:

I have tblLog. It's fields a
Call: text
Freq: single
Mode: text
CID: text
QSL_R: text
Credited: T/F

I need the SQL to return all records where 'Credited' is false, 'QSL_R' NULL or
blank, and whose combination of 'Freq' and 'Mode' for a given 'CID' have 'Credited' =
false, but not if that record has a 'mate' whose 'CID', 'Freq/Mode', 'QSL_R' all
match, and 'Credited' is True.


A Query such as

SELECT * FROM tblLog
WHERE [Credited] = False
AND [QSL_R] IS NOT NULL
AND ([Credited] = FALSE AND NOT EXISTS (SELECT [Call] FROM tblLog AS X
WHERE X.Call = tblLog.Call
AND X.Credited = True));


should work. The NOT EXISTS clause may be slow, and could probably be replaced
by a JOIN but I'd need to mock up a table to test it.


Thanks, John.

After playing with your SQL, it's not quite what I want. I think I probably explained
poorly, plus I realized doing anything with 'Freq' was going to be overly complex
because what I'm actually interested in involves a range of 'Freq'. I added a field
called 'Band' (number) to describe a range of 'Freq' (eg a 'Freq' between 13.9 and 15
falls in the 20 'Band').

Speed isn't an issue, it executes fast enough.

I think the field 'Call' is irrelevant. What I really wanted was the country the call
is in, identified by 'CID' ( Country ID). I changed your query to this:

SELECT *
FROM Log
WHERE [Credited] = False
AND [QSL_R] IS NOT NULL and trim(len([qsl_r] + "")) 0
AND ([Credited] = FALSE AND NOT EXISTS (SELECT [CID] FROM Log AS X
WHERE X.CID = Log.CID
AND X.Credited = True))
ORDER BY cid;

which still isn't right. Maybe another example with reasons would help. If the table
is ordered by CID, the records are

Call Freq Mode CID QSL_R Band Credited
1A0KK 14.210 SSB 1A0 Y 20 True
1A0KK 1O.121 CW 1A0 Y 30 True
1A0KK 18.165 SSB 1A0 Y 17 False
1A0KK 21.295 SSB 1A0 Y 15 False
1A0KK 14.160 SSB 1A0 Y 20 False
1A0KK 14.188 SSB 1A0 20 False

The first 2 should not be chosen because 'Credited' is true.
The third and fourth should be chosen because 'Credited' is false and their band and
mode do not match another record with the same 'CID' whose 'Credited' is false.
The fifth should not be chosen because it's 'Band' and 'Mode' and 'CID' do match a
record whose 'Credited' is true.
The sixth would be rejected because 'QSL_R' is not filled.

None of these were selected by our query.

There is also a problem with 'Mode' as it includes ranges also as for example USB,
LSB, SSB, PHO, AM, FM should all be considered the same mode.

It seems to me that I have a table design problem that may make all this very
difficult. I could add another field to do with 'Mode' what I did with 'Freq'.

What's your opinion?

I can send you a .zip of the .mdb that contains this table if it would help. The .zip
is 270K.
  #4  
Old April 27th, 2010, 02:06 AM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Select query help

On Mon, 26 Apr 2010 16:32:30 -0400, MikeR wrote:




Thanks, John.

After playing with your SQL, it's not quite what I want. I think I probably explained
poorly, plus I realized doing anything with 'Freq' was going to be overly complex
because what I'm actually interested in involves a range of 'Freq'. I added a field
called 'Band' (number) to describe a range of 'Freq' (eg a 'Freq' between 13.9 and 15
falls in the 20 'Band').


It sounds like you may need a non-equi join: a table with fields Band, LowFreq
and HighFreq. You can join it to look up the Band value applicable to this
Freq.

Speed isn't an issue, it executes fast enough.

I think the field 'Call' is irrelevant. What I really wanted was the country the call
is in, identified by 'CID' ( Country ID). I changed your query to this:


I have no idea what to do with that information.

SELECT *
FROM Log
WHERE [Credited] = False
AND [QSL_R] IS NOT NULL and trim(len([qsl_r] + "")) 0
AND ([Credited] = FALSE AND NOT EXISTS (SELECT [CID] FROM Log AS X
WHERE X.CID = Log.CID
AND X.Credited = True))
ORDER BY cid;

which still isn't right. Maybe another example with reasons would help. If the table
is ordered by CID, the records are

Call Freq Mode CID QSL_R Band Credited
1A0KK 14.210 SSB 1A0 Y 20 True
1A0KK 1O.121 CW 1A0 Y 30 True
1A0KK 18.165 SSB 1A0 Y 17 False
1A0KK 21.295 SSB 1A0 Y 15 False
1A0KK 14.160 SSB 1A0 Y 20 False
1A0KK 14.188 SSB 1A0 20 False

The first 2 should not be chosen because 'Credited' is true.
The third and fourth should be chosen because 'Credited' is false and their band and
mode do not match another record with the same 'CID' whose 'Credited' is false.
The fifth should not be chosen because it's 'Band' and 'Mode' and 'CID' do match a
record whose 'Credited' is true.
The sixth would be rejected because 'QSL_R' is not filled.

None of these were selected by our query.


I'd need to spend a lot more time than I have available to dope through all
this!

There is also a problem with 'Mode' as it includes ranges also as for example USB,
LSB, SSB, PHO, AM, FM should all be considered the same mode.

It seems to me that I have a table design problem that may make all this very
difficult. I could add another field to do with 'Mode' what I did with 'Freq'.

What's your opinion?

I can send you a .zip of the .mdb that contains this table if it would help. The .zip
is 270K.


Well, that would go fairly far beyond what I'd consider reasonable for unpaid
volunteer work, and I'm not taking consulting clients at present. Sorry! Maybe
you should repost in a new thread and see if there are other volunteers who
have more time.
--

John W. Vinson [MVP]
  #5  
Old April 27th, 2010, 12:36 PM posted to microsoft.public.access
MikeR
external usenet poster
 
Posts: 147
Default Select query help

John W. Vinson wrote:
On Mon, 26 Apr 2010 16:32:30 -0400, MikeR wrote:


Thanks, John.

After playing with your SQL, it's not quite what I want. I think I probably explained
poorly, plus I realized doing anything with 'Freq' was going to be overly complex
because what I'm actually interested in involves a range of 'Freq'. I added a field
called 'Band' (number) to describe a range of 'Freq' (eg a 'Freq' between 13.9 and 15
falls in the 20 'Band').


It sounds like you may need a non-equi join: a table with fields Band, LowFreq
and HighFreq. You can join it to look up the Band value applicable to this
Freq.


That'll work!

Speed isn't an issue, it executes fast enough.

I think the field 'Call' is irrelevant. What I really wanted was the country the call
is in, identified by 'CID' ( Country ID). I changed your query to this:


I have no idea what to do with that information.


Sorry, what I did was use 'CID' where you were using 'Call'

SELECT *
FROM Log
WHERE [Credited] = False
AND [QSL_R] IS NOT NULL and trim(len([qsl_r] + "")) 0
AND ([Credited] = FALSE AND NOT EXISTS (SELECT [CID] FROM Log AS X
WHERE X.CID = Log.CID
AND X.Credited = True))
ORDER BY cid;

which still isn't right. Maybe another example with reasons would help. If the table
is ordered by CID, the records are

Call Freq Mode CID QSL_R Band Credited
1A0KK 14.210 SSB 1A0 Y 20 True
1A0KK 1O.121 CW 1A0 Y 30 True
1A0KK 18.165 SSB 1A0 Y 17 False
1A0KK 21.295 SSB 1A0 Y 15 False
1A0KK 14.160 SSB 1A0 Y 20 False
1A0KK 14.188 SSB 1A0 20 False

The first 2 should not be chosen because 'Credited' is true.
The third and fourth should be chosen because 'Credited' is false and their band and
mode do not match another record with the same 'CID' whose 'Credited' is false.
The fifth should not be chosen because it's 'Band' and 'Mode' and 'CID' do match a
record whose 'Credited' is true.
The sixth would be rejected because 'QSL_R' is not filled.

None of these were selected by our query.


I'd need to spend a lot more time than I have available to dope through all
this!


Thanks for your time and knowledge. I think you've given me enough of a boot to be
able to complete it.
There is also a problem with 'Mode' as it includes ranges also as for example USB,
LSB, SSB, PHO, AM, FM should all be considered the same mode.

It seems to me that I have a table design problem that may make all this very
difficult. I could add another field to do with 'Mode' what I did with 'Freq'.

What's your opinion?

I can send you a .zip of the .mdb that contains this table if it would help. The .zip
is 270K.


Well, that would go fairly far beyond what I'd consider reasonable for unpaid
volunteer work, and I'm not taking consulting clients at present. Sorry! Maybe
you should repost in a new thread and see if there are other volunteers who
have more time.


I understand. Again thank you!
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:28 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.