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_A LERT_ID, $B$.PREF_ACTIVE _FLAG, MAX($B$.TIMESTA MP_) AS MAX_DATE
From $A$ INNER JOIN $B$ ON $A$.USER_ID=$B$ .USER_ID
Where $A$.Subscribed= 1 and $B$.User_Comm_A lert_ID=1
GROUP BY $A$.USER_ID, $A$.EMAIL, $A$.FIRST_NAME, $A$. LAST_NAME, $A$.COBRAND_ID, $A$.SUBSCRIBED, $B$.USER_COMM_A LERT_ID, $B$.PREF_ACTIVE _FLAG HAVING $B$.PREF_ACTIVE _FLAG=1
1 2354
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_A LERT_ID,
$B$.PREF_ACTIVE _FLAG, MAX($B$.TIMESTA MP_) 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_A lert_ID=1
HAVING $B$.PREF_ACTIVE _FLAG=1
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
Smarty-2.6.7.tar.gz
on a system running WindowsXP SP2.
Apache and PHP tested out fine. After adding Smarty, I ran the
following http://localhost/testphp.php
|
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 I put it in there, I will get no
duplicates (because it is the identity field). The whole point of
this is to find dups.
Thanks for any help.
|
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.
However, as a personal learning project and challenge, I decided to see if I
could code my initial HTM page to call any of the three ASP pages, depending
on the condition of an option group. (3 buttons - id="function", id="sub",
id="class")
I...
|
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 href="lemurs.html">Lemurs</a></li>
<li><a href="chameleons.html">Chameleons</a></li>
</ul>
<ul>
|
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 group header also. The
subreport in the group footer is based on a query. I have code in the group
header that runs a function whose value becomes part of the criteria in the
query for the subreport in the group footer. The value of the function...
| |
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 LDIFDE as a comparison I get the same
results. No members means just that, an empty group. Zero means that the
DirectorySearcher.SizeLimit has been exceeded....
|
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 microsoft.visualbasic.dll
|
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 below it works well at returning whether the
user is directly a member of the group. However, if they are contained inside
of an inherited security group, it returns false because it will not search
recursively.
|
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,
GCP.Name
FROM Gov_Capital_Project GCP,
|
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 same query with
out parameters it runs and it was runing well before in Oracle 8.Also If I
don't use the GROUP BY function but with the parameter, it works also well
?What is the problem? The query is:select t1.id,t2.nad,max(t2.name) as
namefrom...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |