473,769 Members | 3,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

view of max values from many tables

M
I have about 14 tables that I am trying to tie together in a view to
see a user's status in our company.

Joe User:
Email - Active
ADP - Active
Portal - Inactive
etc.

We need to track application access across the company, so we have
tables for each application that contain user info(username,
password(encryp ted), start date, end date, changed date) so that we
can track who has what, and when they were given access as well as
when it was taken away.

Every application table has a userID attached to it.

What I would like to do is to take the userID field and look for their
application access across the company. To do this, i'll have to look
for the max value in each table because someone could be given access,
have it taken away, and be given it again. People move all over the
place here, so we have to be able to track who has what, when, and at
what building.

I started out with trying to left outer join the tables together, but
it didn't work. I tried doing something along the lines of:
select
esarfAppEmail.e mailID,
esarfAppEmail.e sarfUserID,
CASE WHEN esarfAppEmail.e ndDate IS NULL Then 'Active' else 'Inactive'
end as EmailStatus--,
>From esarfAppEmail LEFT OUTER JOIN
esarfUser on esarfAppEmail.e sarfUserID = esarfUser.userI D
where emailID in
(select max(esarfAppEma il.emailID)
from esarfAppEmail
group by esarfAppEmail.e sarfUserID)

And this works, but only if I run it for the Email application. As
soon as I start adding applications, the results go down.

Am I headed in the right direction, or completely off base?

May 22 '07 #1
2 1865
M@ (ma*********@gm ail.com) writes:
I have about 14 tables that I am trying to tie together in a view to
see a user's status in our company.

Joe User:
Email - Active
ADP - Active
Portal - Inactive
etc.

We need to track application access across the company, so we have
tables for each application that contain user info(username,
password(encryp ted), start date, end date, changed date) so that we
can track who has what, and when they were given access as well as
when it was taken away.
Why is there one table per application? Are there other columns that
you did not mention that are different from table to table? For this
problem at least, it would have been easier, if had been one table.

But you could define a view:

SELECT App = 'Email', UserID, StartDate, EndDate, Password, ...
FROM Email
UNION ALL
SELECT 'ADP', UserID, StartDate, EndDate, Password, ...
FROM ADP
UNION ALL
...
What I would like to do is to take the userID field and look for their
application access across the company. To do this, i'll have to look
for the max value in each table because someone could be given access,
have it taken away, and be given it again. People move all over the
place here, so we have to be able to track who has what, when, and at
what building.
I'm not sure really what you are looking for, but to see the records with
the most recent StartDate for each application and user, you could do:

SELECT A.*
FROM AllApps A
JOIN (SELECT App, UserID, MaxStartDate = MAX(StartDate)
FROM AllApps
GROUP BY App, UserID) AS M ON a.App = M.App
AND a.UserID = M.UserID
AND a.StartDate = M.MaxStartDate
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
May 22 '07 #2
M
On May 22, 6:00 pm, Erland Sommarskog <esq...@sommars kog.sewrote:
M@ (mattcush...@gm ail.com) writes:
I have about 14 tables that I am trying to tie together in a view to
see a user's status in our company.
Joe User:
Email - Active
ADP - Active
Portal - Inactive
etc.
We need to track application access across the company, so we have
tables for each application that contain user info(username,
password(encryp ted), start date, end date, changed date) so that we
can track who has what, and when they were given access as well as
when it was taken away.

Why is there one table per application? Are there other columns that
you did not mention that are different from table to table? For this
problem at least, it would have been easier, if had been one table.
Yeah, sorry. Each App has 4 fields in common (UserID, StartDate,
EndDate, Password), but can also have quite a few other fields
associated with the application access.
But you could define a view:

SELECT App = 'Email', UserID, StartDate, EndDate, Password, ...
FROM Email
UNION ALL
SELECT 'ADP', UserID, StartDate, EndDate, Password, ...
FROM ADP
UNION ALL
...
What I would like to do is to take the userID field and look for their
application access across the company. To do this, i'll have to look
for the max value in each table because someone could be given access,
have it taken away, and be given it again. People move all over the
place here, so we have to be able to track who has what, when, and at
what building.

I'm not sure really what you are looking for, but to see the records with
the most recent StartDate for each application and user, you could do:

SELECT A.*
FROM AllApps A
JOIN (SELECT App, UserID, MaxStartDate = MAX(StartDate)
FROM AllApps
GROUP BY App, UserID) AS M ON a.App = M.App
AND a.UserID = M.UserID
AND a.StartDate = M.MaxStartDate
Thanks, I'll try it out.

May 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11261
by: sci | last post by:
Could someone help me by answering the questions below? What's a cursor? What's difference between Query and View? Is a RecordSet just part of a table? Can it be part of a query of view? If the content in a table changed, is it necessary for a old recordset to renew itself by do "Requery()"? Thanks for your help!
3
2063
by: brendan_gallagher_2001 | last post by:
Hi, I have a view(A) and I am trying to do a join on another table (B) to include only rows where date values in view A is greater than in table B. I also want the view to pick up rows in viewA based on date values. Here is what I have so far: SELECT * FROM viewA vw left JOIN tableB tb ON
4
2718
by: stacdab | last post by:
We have a partitioned view with 4 underlying tables. The view and each of the underlying tables are in seperate databases on the same server. Inserts and deletes on the view work fine. We then add insert and delete triggers to each of the underlying tables. The triggers modify a different set of tables in the same database as the view (different than the underlying table). The problem is those triggers aren't fired when inserting or...
6
4387
by: Eugene | last post by:
Summary: ---------- Updates against UNION ALL view does't do branch elimination, but rather reads all the branches (partitions). The case scenario(DB2 V8.1.4a ESE, AIX 5.2): -------------------------------------------- The UNION ALL view (tv) was built on the following three sample tables (t1,t2,t3)
4
4340
by: | last post by:
I have an ACCESS db from a DEXA machine (bone scanner). The data is in seperate tables and I want to link them so that I can query and create one table with all the data I need from the seperate tables. When I try to create a query with multiple tables in design view, if I run it to see the data view, only the names of the columns appear, but no data from the multiple tables that I have queried shows. If I bring only 1 table into design...
2
2910
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to avoid the problem by avoiding the table control or resorting to databound controls that better manage state for me. I hope to understand how to solve the problem by using the Table web control and sticking to the approach of building the table at run...
0
1728
by: teju | last post by:
Hi all, I am trying to populate tree view from the database. Till two levels i can populate it fine but when it reaches third level it doesn't expand. Below is the code, it has been taken from the reference of micrososft Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs) ' Call the appropriate method to populate a node at a particular level. If e.Node.ChildNodes.Count = 0 Then Select Case...
1
1679
by: Tableshavturned | last post by:
Hi this is my first post on the forums. I haven't really developed before with Access 2003 so trouble shooting with this application is not my forte. The issue at hand is, created a star schema with all the IDs in one table for the eight tables I created in design view, the datatype for all the IDs is number in this Table. ID EventID ObsID RecID ActItemID LocID AssgnID ImpctID ProjID
2
9841
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes to open in datasheet view. As an experiment, I deleted all rows in all tables; after that, the query took only seconds to open in both design view and datasheet view. From these facts, I conclude that Access is evaluating the query when I go to...
0
9583
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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,...
0
9860
tracyyun
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...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
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...
1
3955
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
3
2814
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 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...

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.