Solved

Visual Basic SQL Count Query

Posted on 2004-03-31
2
448 Views
Last Modified: 2013-12-25
Hi, I am trying to get the following information, using an Access Database:

sql = "SELECT A.1, A.2, A.3 FROM A"
           
But I also want to get a Count from B Where A.1 = B.1

If I try this:

sql = "SELECT A.1, A.2, A.3, count(B.2) As Number FROM A,B WHERE A.1 = B.1"

I am trying to get a result of all A.1, A.2, A.3 and a count of B.2 where A.1 = B.1

The error I get is:
“you tried to execute a query that does not include the specified expression ‘userName’ as part of an aggregate function"

Any help would be great!

Thanks!
0
Comment
Question by:DOCOOGIE
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 10724391
Hi DOCOOGIE,

You could do:

Select A.1, A.2, A.3, (Select Count(*) From B Where A.1 = B.1) As Number From A

Tim Cottee
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:DOCOOGIE
ID: 10724462
Tim,

Thanks!  You are a lifesaver!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question