PC Review


Reply
Thread Tools Rate Thread

Combine 2 queries

 
 
Sei
Guest
Posts: n/a
 
      25th Sep 2008
I have these two queries with the following SQL:
SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
tbl_LogBasicInfo.rAddID, tbl_LogBasicInfo.mAddID, tbl_ClmtAddress.cAddID,
tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
tbl_ClmtAddress.cZipCode
FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER JOIN tbl_LogBasicInfo ON
tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.mAddID) ON (tbl_Claimant.clmtID =
tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID = tbl_ClmtAddress.clmtID);

and

SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
tbl_LogBasicInfo.mAddID, tbl_LogBasicInfo.rAddID, tbl_ClmtAddress.cAddID,
tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
tbl_ClmtAddress.cZipCode
FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER JOIN tbl_LogBasicInfo ON
tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.rAddID) ON (tbl_Claimant.clmtID =
tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID = tbl_ClmtAddress.clmtID);

How do I combine the two?
Thank you,
 
Reply With Quote
 
 
 
 
Steve Sanford
Guest
Posts: n/a
 
      25th Sep 2008
I would try a union query.

SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
tbl_LogBasicInfo.rAddID, tbl_LogBasicInfo.mAddID, tbl_ClmtAddress.cAddID,
tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
tbl_ClmtAddress.cZipCode FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER
JOIN tbl_LogBasicInfo ON tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.mAddID) ON
(tbl_Claimant.clmtID = tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID =
tbl_ClmtAddress.clmtID);

UNION

SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
tbl_LogBasicInfo.mAddID, tbl_LogBasicInfo.rAddID, tbl_ClmtAddress.cAddID,
tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
tbl_ClmtAddress.cZipCode FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER
JOIN tbl_LogBasicInfo ON tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.rAddID) ON
(tbl_Claimant.clmtID = tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID =
tbl_ClmtAddress.clmtID);



NOTE: You will have to change to SQL mode (view) of the query designer to
create this query.


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


"Sei" wrote:

> I have these two queries with the following SQL:
> SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
> tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
> tbl_LogBasicInfo.rAddID, tbl_LogBasicInfo.mAddID, tbl_ClmtAddress.cAddID,
> tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
> tbl_ClmtAddress.cZipCode
> FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER JOIN tbl_LogBasicInfo ON
> tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.mAddID) ON (tbl_Claimant.clmtID =
> tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID = tbl_ClmtAddress.clmtID);
>
> and
>
> SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
> tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
> tbl_LogBasicInfo.mAddID, tbl_LogBasicInfo.rAddID, tbl_ClmtAddress.cAddID,
> tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
> tbl_ClmtAddress.cZipCode
> FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER JOIN tbl_LogBasicInfo ON
> tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.rAddID) ON (tbl_Claimant.clmtID =
> tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID = tbl_ClmtAddress.clmtID);
>
> How do I combine the two?
> Thank you,

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      25th Sep 2008
I'm sorry. I may be missing something, but the two queries look identical to
me!

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Sei" <(E-Mail Removed)> wrote in message
news:603A9A0F-B843-4F23-BC0D-(E-Mail Removed)...
>I have these two queries with the following SQL:
> SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
> tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
> tbl_LogBasicInfo.rAddID, tbl_LogBasicInfo.mAddID, tbl_ClmtAddress.cAddID,
> tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
> tbl_ClmtAddress.cZipCode
> FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER JOIN tbl_LogBasicInfo
> ON
> tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.mAddID) ON (tbl_Claimant.clmtID
> =
> tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID =
> tbl_ClmtAddress.clmtID);
>
> and
>
> SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
> tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
> tbl_LogBasicInfo.mAddID, tbl_LogBasicInfo.rAddID, tbl_ClmtAddress.cAddID,
> tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
> tbl_ClmtAddress.cZipCode
> FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER JOIN tbl_LogBasicInfo
> ON
> tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.rAddID) ON (tbl_Claimant.clmtID
> =
> tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID =
> tbl_ClmtAddress.clmtID);
>
> How do I combine the two?
> Thank you,



 
Reply With Quote
 
Sei
Guest
Posts: n/a
 
      25th Sep 2008
I only have one Address table but the Log table is asking for the 'residence'
address and 'mailing' address. So in the log table I have mAddID and rAddID
to store the primary key from the Address table.

For the Mailing query I have this line:
tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.mAddID) ON ...

and for the Residence query I have this line:
tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.rAddID) ON ...

That's about the only line they are different

"Douglas J. Steele" wrote:

> I'm sorry. I may be missing something, but the two queries look identical to
> me!




 
Reply With Quote
 
Sei
Guest
Posts: n/a
 
      25th Sep 2008
This didnt work. I created a query in SQL view but when i went to datasheet
view, it only displayed all the records with the same mAddID and cAddID. I
also want to display records with the same rAddID and cAddID.

so if my record has both mAddID and rAddID, i want to see 2 results instead
of one. Hopefully, I'm not too confusing. Thanks, Sei.

"Steve Sanford" wrote:

> I would try a union query.
>
> SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
> tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
> tbl_LogBasicInfo.rAddID, tbl_LogBasicInfo.mAddID, tbl_ClmtAddress.cAddID,
> tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
> tbl_ClmtAddress.cZipCode FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER
> JOIN tbl_LogBasicInfo ON tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.mAddID) ON
> (tbl_Claimant.clmtID = tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID =
> tbl_ClmtAddress.clmtID);
>
> UNION
>
> SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
> tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
> tbl_LogBasicInfo.mAddID, tbl_LogBasicInfo.rAddID, tbl_ClmtAddress.cAddID,
> tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
> tbl_ClmtAddress.cZipCode FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER
> JOIN tbl_LogBasicInfo ON tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.rAddID) ON
> (tbl_Claimant.clmtID = tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID =
> tbl_ClmtAddress.clmtID);
>
>
>
> NOTE: You will have to change to SQL mode (view) of the query designer to
> create this query.
>
>
> HTH
> --
> Steve S
> --------------------------------
> "Veni, Vidi, Velcro"
> (I came; I saw; I stuck around.)
>
>
> "Sei" wrote:
>
> > I have these two queries with the following SQL:
> > SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
> > tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
> > tbl_LogBasicInfo.rAddID, tbl_LogBasicInfo.mAddID, tbl_ClmtAddress.cAddID,
> > tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
> > tbl_ClmtAddress.cZipCode
> > FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER JOIN tbl_LogBasicInfo ON
> > tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.mAddID) ON (tbl_Claimant.clmtID =
> > tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID = tbl_ClmtAddress.clmtID);
> >
> > and
> >
> > SELECT tbl_LogBasicInfo.logID, tbl_LogBasicInfo.logTypeID,
> > tbl_LogBasicInfo.logSSN, tbl_LogBasicInfo.clmtID, tbl_LogBasicInfo.clmID,
> > tbl_LogBasicInfo.mAddID, tbl_LogBasicInfo.rAddID, tbl_ClmtAddress.cAddID,
> > tbl_ClmtAddress.cAddress, tbl_ClmtAddress.cCity, tbl_ClmtAddress.cState,
> > tbl_ClmtAddress.cZipCode
> > FROM tbl_Claimant INNER JOIN (tbl_ClmtAddress INNER JOIN tbl_LogBasicInfo ON
> > tbl_ClmtAddress.cAddID = tbl_LogBasicInfo.rAddID) ON (tbl_Claimant.clmtID =
> > tbl_LogBasicInfo.clmtID) AND (tbl_Claimant.clmtID = tbl_ClmtAddress.clmtID);
> >
> > How do I combine the two?
> > Thank you,

 
Reply With Quote
 
pietlinden@hotmail.com
Guest
Posts: n/a
 
      26th Sep 2008
If you want to see the duplicates, you need to use

SELECT...
FROM
WHERE
UNION ALL
SELECT...
FROM
WHERE

 
Reply With Quote
 
Steve Sanford
Guest
Posts: n/a
 
      26th Sep 2008
Oops.... I had another PBKAC episode


--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


"(E-Mail Removed)" wrote:

> If you want to see the duplicates, you need to use
>
> SELECT...
> FROM
> WHERE
> UNION ALL
> SELECT...
> FROM
> WHERE
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to combine queries???? Joseph Microsoft Access Queries 2 24th Apr 2010 05:05 PM
Combine queries KD Microsoft Access Queries 2 29th Oct 2009 10:57 PM
Help - Trying to Combine 3 Queries into 1 Anonymous Microsoft Access 4 1st Nov 2005 04:46 PM
Use a sub-qry to combine all three queries JoJo Sharp via AccessMonster.com Microsoft Access 4 1st Jul 2005 09:38 PM
Combine 3 Queries into one PC Microsoft Access Queries 1 12th Aug 2003 12:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:23 PM.