Need help pulling data from two tables

V

VMS Man

I have two tables (DONORS & GIFTS). Both have a common field (DONORID). I
want to read each record in GIFTS and then get the associated data in DONORS
that matches the DONORID (ADDRESS, CITY, STATE, ZIP). I've tried different
queries, but each one returns no records. There is currently a relationship
between the tables using the DONORID field. The query I've tried is:
SELECT GIFTS.Donorid, GIFTS.donorname, DONORS.PRIADD1, DONORS.PRICITY,
DONORS.PRISTATE, DONORS.PRIPOSTAL
FROM GIFTS INNER JOIN DONORS ON GIFTS.Donorid = DONORS.DONORID
WHERE (GIFTS.Donorid)=(DONORS.donorid);

Can anyone tell me what I'm doing wrong and how to fix it? Thanks!
 
S

Sunny

SELECT GIFTS.Donorid, DONORS.donorname, DONORS.PRIADD1, DONORS.PRICITY,
DONORS.PRISTATE, DONORS.PRIPOSTAL
FROM GIFTS INNER JOIN DONORS ON GIFTS.Donorid = DONORS.DONORID
 
P

Paul

I tried that and the result is 1 null record.

Sunny said:
SELECT GIFTS.Donorid, DONORS.donorname, DONORS.PRIADD1, DONORS.PRICITY,
DONORS.PRISTATE, DONORS.PRIPOSTAL
FROM GIFTS INNER JOIN DONORS ON GIFTS.Donorid = DONORS.DONORID
 
M

Marshall Barton

VMS Man said:
I have two tables (DONORS & GIFTS). Both have a common field (DONORID). I
want to read each record in GIFTS and then get the associated data in DONORS
that matches the DONORID (ADDRESS, CITY, STATE, ZIP). I've tried different
queries, but each one returns no records. There is currently a relationship
between the tables using the DONORID field. The query I've tried is:
SELECT GIFTS.Donorid, GIFTS.donorname, DONORS.PRIADD1, DONORS.PRICITY,
DONORS.PRISTATE, DONORS.PRIPOSTAL
FROM GIFTS INNER JOIN DONORS ON GIFTS.Donorid = DONORS.DONORID
WHERE (GIFTS.Donorid)=(DONORS.donorid);


I don't see anything seriously wrong with that query.

Some points though:
The Join is already selecting the matching records, which
makes the Where clause redundant at best (get rid of it).

The DonorName field should be in the Donors table, not in
the Gifts table. Either the query is wrong about that or
your table structure is not normal.

The only serious thought I have about why the query doesn't
return any records is the possibility that the DonorID field
in one table is a different data type than it is in the
other table. Double check that it same data type (Long
Integer?) in **both** tables.
 
P

paul

I thank everyone for their input. Not knowing where to look, you all pointed
me in the right direction. It was the data type of the DONORID field. It
was originally defined as a text field, so I took your advice and changed it
to a "long integer number" and it worked. Thanks again!

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top