I am attempting to pull all users over the age of 30 from a table. I want the results to be returned off of their membership status and recent activity. Their membership status is stored in a seperate table (Payment). Some users have more than one membership status record, while others might not have any at all.
LEFT JOIN seems like a possible solution, however, if a user has more than one membership status record, it is returning multiple results for that user (when I only want 1 result for that user).
Here is the code that I have so far.
SELECT Users.UserID FROM Users LEFT JOIN Payment ON Users.UserID = Payment.UserID AND Users.Age > 30 AND Payment.PaymentExpirationDate > '3/28/2004' ORDER BY Payment.MembershipNumber DESC, Users.LastActive DESC
Payment.MembershipNumber - INT Field. This is the membership status for the user, if the user has any membership records.
Users.LastActive - Date/Time Field. This is the recent active for the user.
The data is being returned right now is:
UserID
=====
3
8
12
12
12
9
9
1
... and so on, when it should look like ...
UserID
=====
3
8
12
9
1
I hope this makes sense. Thanks for your time.
Jamesif a user has more than one membership status record, which one do you want?|||I need the first membership status record that has a PaymentExpirationDate closest to '3/28/2004'.|||select U.UserID
, U.lastActive
, P.PaymentExpirationDate
from Users U
left
join Payment P
on U.UserID
= P.UserID
and P.PaymentExpirationDate
> '3/28/2004'
where U.Age > 30
and P.PaymentExpirationDate
= ( select min(PaymentExpirationDate)
from Payment
where UserID = P.UserID
and PaymentExpirationDate
> '3/28/2004' )
order
by U.LastActive desc
Showing posts with label membership. Show all posts
Showing posts with label membership. Show all posts
Tuesday, March 20, 2012
Monday, February 20, 2012
public role membership
why does
sp_helprolemember 'public'
show no results, even though through the gui you can see that all the users
have tat role?Jason,
Since 'public' is defined to always contain everyone with access to a
database, there is no specific assignment to make them role members. So
sp_helprolemember has no rows to read and report on.
FWIW, if I assign a Windows Group to be a role member, only the Windows
Group (but not the logins that are members of the Windows Group) are
reported on by sp_helprolemember.
RLF
"Jason" <Jason@.discussions.microsoft.com> wrote in message
news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
> why does
> sp_helprolemember 'public'
> show no results, even though through the gui you can see that all the
> users
> have tat role?|||thank you
"Russell Fields" wrote:
> Jason,
> Since 'public' is defined to always contain everyone with access to a
> database, there is no specific assignment to make them role members. So
> sp_helprolemember has no rows to read and report on.
> FWIW, if I assign a Windows Group to be a role member, only the Windows
> Group (but not the logins that are members of the Windows Group) are
> reported on by sp_helprolemember.
> RLF
> "Jason" <Jason@.discussions.microsoft.com> wrote in message
> news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
>
>
sp_helprolemember 'public'
show no results, even though through the gui you can see that all the users
have tat role?Jason,
Since 'public' is defined to always contain everyone with access to a
database, there is no specific assignment to make them role members. So
sp_helprolemember has no rows to read and report on.
FWIW, if I assign a Windows Group to be a role member, only the Windows
Group (but not the logins that are members of the Windows Group) are
reported on by sp_helprolemember.
RLF
"Jason" <Jason@.discussions.microsoft.com> wrote in message
news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
> why does
> sp_helprolemember 'public'
> show no results, even though through the gui you can see that all the
> users
> have tat role?|||thank you
"Russell Fields" wrote:
> Jason,
> Since 'public' is defined to always contain everyone with access to a
> database, there is no specific assignment to make them role members. So
> sp_helprolemember has no rows to read and report on.
> FWIW, if I assign a Windows Group to be a role member, only the Windows
> Group (but not the logins that are members of the Windows Group) are
> reported on by sp_helprolemember.
> RLF
> "Jason" <Jason@.discussions.microsoft.com> wrote in message
> news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
>
>
public role membership
why does
sp_helprolemember 'public'
show no results, even though through the gui you can see that all the users
have tat role?Jason,
Since 'public' is defined to always contain everyone with access to a
database, there is no specific assignment to make them role members. So
sp_helprolemember has no rows to read and report on.
FWIW, if I assign a Windows Group to be a role member, only the Windows
Group (but not the logins that are members of the Windows Group) are
reported on by sp_helprolemember.
RLF
"Jason" <Jason@.discussions.microsoft.com> wrote in message
news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
> why does
> sp_helprolemember 'public'
> show no results, even though through the gui you can see that all the
> users
> have tat role?|||thank you
"Russell Fields" wrote:
> Jason,
> Since 'public' is defined to always contain everyone with access to a
> database, there is no specific assignment to make them role members. So
> sp_helprolemember has no rows to read and report on.
> FWIW, if I assign a Windows Group to be a role member, only the Windows
> Group (but not the logins that are members of the Windows Group) are
> reported on by sp_helprolemember.
> RLF
> "Jason" <Jason@.discussions.microsoft.com> wrote in message
> news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
> > why does
> >
> > sp_helprolemember 'public'
> >
> > show no results, even though through the gui you can see that all the
> > users
> > have tat role?
>
>
sp_helprolemember 'public'
show no results, even though through the gui you can see that all the users
have tat role?Jason,
Since 'public' is defined to always contain everyone with access to a
database, there is no specific assignment to make them role members. So
sp_helprolemember has no rows to read and report on.
FWIW, if I assign a Windows Group to be a role member, only the Windows
Group (but not the logins that are members of the Windows Group) are
reported on by sp_helprolemember.
RLF
"Jason" <Jason@.discussions.microsoft.com> wrote in message
news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
> why does
> sp_helprolemember 'public'
> show no results, even though through the gui you can see that all the
> users
> have tat role?|||thank you
"Russell Fields" wrote:
> Jason,
> Since 'public' is defined to always contain everyone with access to a
> database, there is no specific assignment to make them role members. So
> sp_helprolemember has no rows to read and report on.
> FWIW, if I assign a Windows Group to be a role member, only the Windows
> Group (but not the logins that are members of the Windows Group) are
> reported on by sp_helprolemember.
> RLF
> "Jason" <Jason@.discussions.microsoft.com> wrote in message
> news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
> > why does
> >
> > sp_helprolemember 'public'
> >
> > show no results, even though through the gui you can see that all the
> > users
> > have tat role?
>
>
public role membership
why does
sp_helprolemember 'public'
show no results, even though through the gui you can see that all the users
have tat role?
Jason,
Since 'public' is defined to always contain everyone with access to a
database, there is no specific assignment to make them role members. So
sp_helprolemember has no rows to read and report on.
FWIW, if I assign a Windows Group to be a role member, only the Windows
Group (but not the logins that are members of the Windows Group) are
reported on by sp_helprolemember.
RLF
"Jason" <Jason@.discussions.microsoft.com> wrote in message
news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
> why does
> sp_helprolemember 'public'
> show no results, even though through the gui you can see that all the
> users
> have tat role?
|||thank you
"Russell Fields" wrote:
> Jason,
> Since 'public' is defined to always contain everyone with access to a
> database, there is no specific assignment to make them role members. So
> sp_helprolemember has no rows to read and report on.
> FWIW, if I assign a Windows Group to be a role member, only the Windows
> Group (but not the logins that are members of the Windows Group) are
> reported on by sp_helprolemember.
> RLF
> "Jason" <Jason@.discussions.microsoft.com> wrote in message
> news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
>
>
sp_helprolemember 'public'
show no results, even though through the gui you can see that all the users
have tat role?
Jason,
Since 'public' is defined to always contain everyone with access to a
database, there is no specific assignment to make them role members. So
sp_helprolemember has no rows to read and report on.
FWIW, if I assign a Windows Group to be a role member, only the Windows
Group (but not the logins that are members of the Windows Group) are
reported on by sp_helprolemember.
RLF
"Jason" <Jason@.discussions.microsoft.com> wrote in message
news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
> why does
> sp_helprolemember 'public'
> show no results, even though through the gui you can see that all the
> users
> have tat role?
|||thank you
"Russell Fields" wrote:
> Jason,
> Since 'public' is defined to always contain everyone with access to a
> database, there is no specific assignment to make them role members. So
> sp_helprolemember has no rows to read and report on.
> FWIW, if I assign a Windows Group to be a role member, only the Windows
> Group (but not the logins that are members of the Windows Group) are
> reported on by sp_helprolemember.
> RLF
> "Jason" <Jason@.discussions.microsoft.com> wrote in message
> news:FADD06B3-9D06-4930-93B0-4CA7C26B1A1F@.microsoft.com...
>
>
Labels:
database,
doessp_helprolemember,
gui,
membership,
microsoft,
mysql,
oracle,
public,
publicshow,
role,
server,
sql,
tat,
usershave
Subscribe to:
Posts (Atom)