Need help pulling data from two tables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
SELECT GIFTS.Donorid, DONORS.donorname, DONORS.PRIADD1, DONORS.PRICITY,
DONORS.PRISTATE, DONORS.PRIPOSTAL
FROM GIFTS INNER JOIN DONORS ON GIFTS.Donorid = DONORS.DONORID
 
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
 
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.
 
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
 
Back
Top