G
Guest
Hello,
I am trying to ask a fairly complicated question with a correlated subquery
in Access 2003. This is my first endeavor into SQL, I have always been able
to use design view to run my queries. I am trying to select boats that have
landings in a specific port and all of the other ports they landed in. To
rephrase: If boat x has data in port y, please return all data in all ports
for that boat.
Here is my current code:
SELECT Moss_Allports.DRVID, Moss_Allports.S_N_PC_A, Sum(Moss_Allports.RNDWT)
AS SumOfRNDWT, Moss_Allports.YEAR, Sum(Moss_Allports.REV_ADJ) AS SumOfREV_ADJ
FROM Moss_Allports
WHERE EXISTS (SELECT Moss_Allports.DRVID, Moss_Allports.S_N_PC_A, YEAR
FROM Moss_Allports
GROUP BY Moss_Allports.DRVID, Moss_Allports.S_N_PC_A, Moss_Allports.YEAR
HAVING (((Moss_Allports.YEAR)=1981)) AND (((Moss_Allports.S_N_PC_A)=22))
GROUP BY Moss_Allports.DRVID, Moss_Allports.S_N_PC_A, Moss_Allports.YEAR
HAVING (((Moss_Allports.YEAR)=1981));
With this code, I am still getting all boats in 1981 whether they landed in
port y or not. I only want ports that landed in port y, and I want all of the
other ports those boats went to.
Thanks,
Rebecca
I am trying to ask a fairly complicated question with a correlated subquery
in Access 2003. This is my first endeavor into SQL, I have always been able
to use design view to run my queries. I am trying to select boats that have
landings in a specific port and all of the other ports they landed in. To
rephrase: If boat x has data in port y, please return all data in all ports
for that boat.
Here is my current code:
SELECT Moss_Allports.DRVID, Moss_Allports.S_N_PC_A, Sum(Moss_Allports.RNDWT)
AS SumOfRNDWT, Moss_Allports.YEAR, Sum(Moss_Allports.REV_ADJ) AS SumOfREV_ADJ
FROM Moss_Allports
WHERE EXISTS (SELECT Moss_Allports.DRVID, Moss_Allports.S_N_PC_A, YEAR
FROM Moss_Allports
GROUP BY Moss_Allports.DRVID, Moss_Allports.S_N_PC_A, Moss_Allports.YEAR
HAVING (((Moss_Allports.YEAR)=1981)) AND (((Moss_Allports.S_N_PC_A)=22))
GROUP BY Moss_Allports.DRVID, Moss_Allports.S_N_PC_A, Moss_Allports.YEAR
HAVING (((Moss_Allports.YEAR)=1981));
With this code, I am still getting all boats in 1981 whether they landed in
port y or not. I only want ports that landed in port y, and I want all of the
other ports those boats went to.
Thanks,
Rebecca