473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA SQL - Filter Group By Over entire Group

28 New Member
Good Morning Pro's,

I am trying to write a script that selects a group based on the criteria within that group. I'm looking to pull in only records that meet that criteria.
Expand|Select|Wrap|Line Numbers
  1. SELECT ColumnA
  2. FROM Table
  3. GROUP BY ColumnA
  4. HAVING ColumnA = 'A'
With the GROUP BY, SQL will pull in my GROUP even if there are two records with 'A' or 'B', rightfully so. I'm trying to only select the group when all Columns meet the criteria of 'A'. In otherwards, if there is a 'B' in the Group, I'd like to NOT SELECT it.

Any creative solutions are welcome. Thanks guys!

P
Apr 3 '14 #1
3 1326
NeoPa
32,557 Recognized Expert Moderator MVP
Try something like this :
Expand|Select|Wrap|Line Numbers
  1. SELECT Min([ColumnA]) AS [MinColA]
  2. FROM   [Table]
  3. HAVING (Max([ColumnA])='A')
Apr 3 '14 #2
pwag
28 New Member
Hi NeoPa,

Thanks! Exactly what I needed. I used this(a variation of your example):
Expand|Select|Wrap|Line Numbers
  1. HAVING (Count(ColumnA))=(SELECT Count(ColumnA) FROM Table WHERE ID = ID);
Apr 3 '14 #3
NeoPa
32,557 Recognized Expert Moderator MVP
I must assume that the actual situation is a little harder to explain so the simpler expedient of comparing the Max() to a specific value (that I suggested) wouldn't work in real life. In that case you've come up with a clever work around.

Typically, I wouldn't recommend using a subquery where it can be done another way but, as I say, I expect it is necessary in your case in spite of the simplified question.

Congratulations on getting by with a simplified question too. So many that try end up causing more confusion than they avoid, but in this case it worked well.
Apr 3 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1253
by: D. K. Mishra | last post by:
I am trying to author some MathMl pages. I have created some pages using some templates that I got from Design Science's web site. The pages work fine in both Internet Explorer 6.0 using Mathplayer...
4
1684
by: Russ Ferrill | last post by:
I have a C# application in which I need to add one Active Directory group as a member of another group. I have tried using the same steps that work for adding a user to a group, but that isn't...
3
4415
by: shiv | last post by:
Hi all, I am able to read groups in the domain but not able to read the members within each group. can somebody help? here goes the code DirectoryEntry m_obDirEntry=new DirectoryEntry...
4
1771
by: Xavier | last post by:
hello, in a string which i read from a textfile there are some lines, which must be eliminated. The content of the stringvariable is for example : myString=" --comment 1 Update ........
3
4097
by: Sebastian | last post by:
Hello all I have a report where I have two nested groups. I know there are only three standard options for running sum: None, Over Group and Over All. I have a MyTextBox in detail section where...
0
1613
by: damian | last post by:
I have a ListView and i am grouping my data using ListViewGroup. I have a problem in that if the group is empty, the group headings are not shown at all, so i cannot select any data at all for...
2
4563
by: antem | last post by:
I receive only members from domain global goup in wich my NT-Account is too. If domain global group belongs to a foreigner domain i get no members. Perhaps I will not be able cause I got not enaugh...
3
10357
by: chibbie23 | last post by:
I wanted to display the first record of a group in the group header without appearing again in the body. I want to do this because the client wanted the name to appear just once. e.g. ...
1
1052
by: jana89 | last post by:
I have a table named Usage with datafield name dateTime. i want to grab the dateTime data into a comboBox named cbDate. the dateTime datatype is in Varchar(45) and it looks like this, 2013-01-29...
0
7264
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7166
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7543
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7106
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5689
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.