Minggu, 03 Februari 2013

Re: [MS_AccessPros] Combine 2 queries into 1 single query

 

Phi on-

Why not just add the filter for District 11 to the first query?

John Viescas

Sent from my iPad

On Feb 3, 2013, at 23:24, "saigonf7q5" saigonf7q5@yahoo.com> wrote:

My task is to pull only the records in District11. I thought the query Step1 below would do that. However it pulled all Districts instead. I then have to add a second query(Step2)to filter it to get the correct result.

I guess the 2 steps can be combined into 1 single query by adding the Group By and Having clause to the first query. If that can be done, how the query can be rewritten? (I tried, but still having trouble to get it right).

Phucon

Step1

SELECT A.DISTINCT A.eID, A.eNAME, A.eDate, A.eCITY, A.eSTATE, A.eDistrict
FROM tblATTRIBUTES AS A
WHERE A.eID In (SELECT T.tID FROM tblTOP AS T WHERE 20120131 BETWEEN T.STARTDate AND T.ENDDate)
AND 20120131 BETWEEN A.STARTdate AND A.ENDDate AND A.eDistrict = 11 AND A.IND1 = 1 AND A.eIND2 = 2
ORDER BY A.eDistrict, A.eSTATE;

Step2

SELECT eID, eNAME, eDate, CITY, eSTATE, eDistrict
FROM Step1
WHERE eDistrict =11

------------------------------------

Yahoo! Groups Links

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar