PC Review


Reply
Thread Tools Rate Thread

conditional join

 
 
Conditional join
Guest
Posts: n/a
 
      5th Feb 2009
In Excel, I can do a conditional lookup by using an IF statement saying if
column A (table #1) = "football", lookup in table #2 and return matched
value, otherwise lookup column H (table #1) and return value from Table #2.

I'm trying to replicate in Access, but I don't know how. In access, I have
Table 1 joined to Table 2. As it is joined, it knows only to return values
that are matched by the joined field. Is it possible to code Access to do
the same as I described above where it knows to return values from Table #2
with the condition that if it doesn't match, use another field to match to
Table #2.
 
Reply With Quote
 
 
 
 
BruceM
Guest
Posts: n/a
 
      5th Feb 2009
Most likely yes, but you may need to be less abstract in describing the
situation. You wrote:
"it knows only to return values that are matched by the joined field"
What exactly is "it"?

I don't quite follow the Excel description, so I can't translate into
Access. I think you're talking about VLookup where Table #2 is the range
examined by the VLookup formula. Access has DLookup, which is quite a bit
different, but then so is Access from Excel.

In general terms, what real-world entity's data is stored in Table #1, and
what related data are stored in Table #2? Once that is described, give some
specific examples of what you hope to accomplish. Access is a program for
creating relational database applications, and can return any specified
value, but that specification can occur in a variety of ways, including
queries and VBA code.

"Conditional join" <Conditional (E-Mail Removed)> wrote in
message news:7E9E27D6-6DC2-4F43-8E52-(E-Mail Removed)...
> In Excel, I can do a conditional lookup by using an IF statement saying if
> column A (table #1) = "football", lookup in table #2 and return matched
> value, otherwise lookup column H (table #1) and return value from Table
> #2.
>
> I'm trying to replicate in Access, but I don't know how. In access, I
> have
> Table 1 joined to Table 2. As it is joined, it knows only to return
> values
> that are matched by the joined field. Is it possible to code Access to do
> the same as I described above where it knows to return values from Table
> #2
> with the condition that if it doesn't match, use another field to match to
> Table #2.


 
Reply With Quote
 
 
 
 
KARL DEWEY
Guest
Posts: n/a
 
      6th Feb 2009
A LEFT JOIN will pull all records from left table and only those of the right
that match the left.
--
KARL DEWEY
Build a little - Test a little


"Conditional join" wrote:

> In Excel, I can do a conditional lookup by using an IF statement saying if
> column A (table #1) = "football", lookup in table #2 and return matched
> value, otherwise lookup column H (table #1) and return value from Table #2.
>
> I'm trying to replicate in Access, but I don't know how. In access, I have
> Table 1 joined to Table 2. As it is joined, it knows only to return values
> that are matched by the joined field. Is it possible to code Access to do
> the same as I described above where it knows to return values from Table #2
> with the condition that if it doesn't match, use another field to match to
> Table #2.

 
Reply With Quote
 
Paul Shapiro
Guest
Posts: n/a
 
      6th Feb 2009
You can't make the join conditional, but you can make the output column
conditional. You need to provide table structure for accurate help, but
maybe something like this:

Select
IIf(Table1.ColumnA="football", Table2.ColumnZ, Table1.ColumnH) as
OutputAA
From Table1 Inner Join Table2 On ...

If Table2 ONLY has matching rows for Table1 when Table1.ColumnA="football",
then you need to use an outer join. A left outer join will return all rows
from Table1, with matching rows for Table2 and nulls if there isn't any
matching row in Table2. Again, depending on details, it could be something
like:

Select
nz(Table2.ColumnZ, Table1.ColumnH) as OutputAA
From Table1 Left Join Table2 On ...

If Table2 doesn't match except when Table1=football, you can use the nz
function which returns Table2.ColumnZ if that value is not null, and
Table1.ColumnH if Table2.ColumnZ is null.

"Conditional join" <Conditional (E-Mail Removed)> wrote in
message news:7E9E27D6-6DC2-4F43-8E52-(E-Mail Removed)...
> In Excel, I can do a conditional lookup by using an IF statement saying if
> column A (table #1) = "football", lookup in table #2 and return matched
> value, otherwise lookup column H (table #1) and return value from Table
> #2.
>
> I'm trying to replicate in Access, but I don't know how. In access, I
> have
> Table 1 joined to Table 2. As it is joined, it knows only to return
> values
> that are matched by the joined field. Is it possible to code Access to do
> the same as I described above where it knows to return values from Table
> #2
> with the condition that if it doesn't match, use another field to match to
> Table #2.


 
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
Join Queries - can you join two tables with similar records, not an exact match? John Goodrich Microsoft Access Queries 1 15th Sep 2004 07:24 AM
cross join? full join? or something like that? Alejandra Parra Microsoft Access Queries 1 17th Jun 2004 06:22 AM
Left Join with Inner Join not supported? Mark Microsoft Access Queries 2 15th Nov 2003 11:48 AM
possible join visual basic net form and c sharp join?? jose Microsoft Dot NET 2 6th Nov 2003 05:46 PM
Access Not Showing Up Records for Rt Join or Inner Join Ker Microsoft Access Queries 2 18th Oct 2003 03:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:53 AM.