473,508 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Group By Function

2 New Member
I'm trying to pull the latest record from a preference table, and check to see if that user is subscribed to emails, and they have a preference of 1. Also their preference active flag must be 1.

When I use the MAX function, it forces me to use group by as well. I also get errors unless I group by all the fields I'm selecting. Is there a better way to write this code? Inner query maybe?


Select DISTINCT $A$.USER_ID, $A$.EMAIL, $A$.FIRST_NAME, $A$. LAST_NAME, $A$.COBRAND_ID, $A$.SUBSCRIBED, $B$.USER_COMM_ALERT_ID, $B$.PREF_ACTIVE_FLAG, MAX($B$.TIMESTAMP_) AS MAX_DATE

From $A$ INNER JOIN $B$ ON $A$.USER_ID=$B$.USER_ID

Where $A$.Subscribed=1 and $B$.User_Comm_Alert_ID=1

GROUP BY $A$.USER_ID, $A$.EMAIL, $A$.FIRST_NAME, $A$. LAST_NAME, $A$.COBRAND_ID, $A$.SUBSCRIBED, $B$.USER_COMM_ALERT_ID, $B$.PREF_ACTIVE_FLAG HAVING $B$.PREF_ACTIVE_FLAG=1
Jan 16 '07 #1
1 2346
i2eye
5 New Member
Have you tried using Analytic Functions? See if this works... not sure with the syntax of your table... you might have to play with it.

Select DISTINCT $A$.USER_ID, $A$.EMAIL, $A$.FIRST_NAME, $A$. LAST_NAME,
$A$.COBRAND_ID, $A$.SUBSCRIBED, $B$.USER_COMM_ALERT_ID,
$B$.PREF_ACTIVE_FLAG, MAX($B$.TIMESTAMP_) OVER (PARTITION BY $B$.TIMESTAMP_)

From $A$ INNER JOIN $B$ ON $A$.USER_ID=$B$.USER_ID

Where $A$.Subscribed=1 and $B$.User_Comm_Alert_ID=1

HAVING $B$.PREF_ACTIVE_FLAG=1
Jan 17 '07 #2

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

Similar topics

2
14146
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
3
17352
by: Robby McGehee | last post by:
I need this to work: SELECT FROM WITH (NOLOCK) where ='a' GROUP BY , HAVING COUNT () > 1 The problem is that I get an error that needs to be in the GROUP BY clause or aggregate function. if...
19
1994
by: What-a-Tool | last post by:
I have a school project (ASP) in which I have to call three different ASP pages from three different and identical (except for the form "action", obviously) HTM pages. This I have no problem with....
16
4411
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
0
1651
by: Melissa | last post by:
I have a grouped report with a subreport in the group footer. The report is set to start a new page for each group. All the labels for fields are in the group header and there is a subreport in the...
9
10808
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
0
915
by: Rody Reulen | last post by:
When i call the function: ADGroupCreate("Group1", "Group one") I got the following error message: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in...
3
1636
by: weeims | last post by:
Hi, When a user visits my site (ASP.NET + VB.NET), I need to know if they are in a particular AD security group in order to display the pertinant information. When I call UserLookup in code...
12
25220
by: Bill Moran | last post by:
Hey all. I've hit an SQL problem that I'm a bit mystified by. I have two different questions regarding this problem: why? and how do I work around it? The following query: SELECT GCP.id,...
6
12143
by: MM | last post by:
Hello users. I have a query that I can run and see the result on the grid on design time, but when i run the program i get the folowing message:ORA-00979: not a GROUP BY expression. When I run the...
0
7125
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
7388
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
7049
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
5631
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
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
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 ...
0
422
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.