0

I'll try to be as specific as i can here, so here's the query using MsAccess.

SELECT MsThread.ID, 
       MsThread.ThreadName, 
COUNT(MsThread.ThreadName) AS TotalPost 
FROM MsThread 
LEFT OUTER JOIN MsPosts 
ON MsThread.ThreadName = MsPosts.ThreadName 
GROUP BY MsThread.ID, MsThread.ThreadName, MsThread.ThreadCategory

When I ran the query in MsAccess it returns this:enter image description here

It shows that I have 4 rows ( # of threads ), and the number 5,2,1,1 is the number of posts with specified threads. Here I've been trying to get the resultset to return 4 instead of 9 so I can loop it without no invalid cursor state error.

rs.last();
int row = rs.getRow();

that returns 8, so i am guessing its returning how many process thats done. so how do i get it to return 4 similar to the COUNT function?

Thanks a lot!!

1
  • Just so you're aware, the rows returning TotalPost = 1 are not guaranteed to actually have a row. Your use of LEFT JOIN means that rows in MsPosts aren't required, so if there isn't a row it just counts the single row in MsThread. I also doubt that that's the query you're running, giving that threadcategory is shown in your results, but the column isn't part of your SELECT list. Dec 31, 2013 at 6:44

1 Answer 1

0

rs, I'm assuming, is the resultant recordset that your SQL returns? If so, you can do:

rs.MoveFirst
rs.MoveLast

X = rs.RecordCount

X should equal 4 in this case, since you have 4 records in your recordset.

I don't think you want to use "row" as a variable name, as that is a reserved word and will probably cause issues when you try to reference it. Make your life easier and call it "RowX" or something that's not reserved.

2
  • Hey how do you do so in JSP? I can't use MoveFirst and MoveLast.
    – kenlz
    Jan 1, 2014 at 16:54
  • This question was tagged with MS Access and SQL. You should edit ti and tag it with JSP, I don't know that language at all. Sorry. :o( Jan 2, 2014 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.