[mso] Re: AccessSQL

Glenda--

How about this?:

SELECT tblCOMM.UID, em.comm AS email, tblCOMM.comm AS phone
FROM tblCOMM INNER JOIN [SELECT tblCOMM.UID, tblCOMM.commID, tblCOMM.comm
FROM tblCOMM
WHERE (((tblCOMM.commID) In (SELECT max(commid) from tblComm where
type='em')) AND ((tblCOMM.type)="em"))]. AS em ON tblCOMM.UID = em.UID
WHERE (((tblCOMM.type)="ph") AND ((tblCOMM.active)=-1));

--Jim 

-----Original Message-----
From: mso-bounce@xxxxxxxxxxxxx [mailto:mso-bounce@xxxxxxxxxxxxx] On Behalf
Of Glenda Wells
Sent: Monday, July 18, 2005 8:47 AM
To: mso@xxxxxxxxxxxxx
Subject: [mso] AccessSQL 

I'm still feeling my way around writing SQL queries in reports and
appreciating all ya'll helping.

I have telephone and email in the same table

I'd like to extract the most recent email by commID (this would be the
maximum record) and the Active telephone of which there can only be one.

I THINK this needs a query/subquery with a join to get the max email as well
as another subquery to get the active phone.

Here's what the table looks like

tblCOMM
UID     commID  type    active  comm
A001    1001            em                      gwells@xxxxxxxxxxx
A001    1002            em                      gwells@xxxxxxx
A001    1003            em                      gwells@xxxxxxx
A001    1004            ph      -1              386-822-7088
A001    1005            ph                      386-822-7126

My desired result is
UID, email, phone
A001, gwells@xxxxxxx, 386-822-7088


I have this which (I hope) gets me the email address but how do I get phone
number too?

SELECT tblCOMM.UID, tblCOMM.comm
FROM tblCOMM
WHERE (((tblCOMM.UID)=3D(SELECT
max(b.commID) FROM tblCOMM b WHERE b.UID =3D tblCOMM.UID)) AND
((tblCOMM.type)=3D"em"));


*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to mso-request@xxxxxxxxxxxxx
with the word "unsubscribe" (without the quotes) in the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will also
allow you to change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation
with instructions.  Once you are a member of the files group, you can go
here to upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes) in 
the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will also allow 
you to change your email settings to digest or vacation (no mail).
http://www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

Other related posts: