Hi All,
I have a 2 tables namely Employee and reports. An employee will/can have multiple reports associated with him for a particular month. I need to fetch the the employee details and the last (or latest) report details for that month.
If for e.g Employee table has 100 entries, i will have (1000 * 12 month * 30 reports/month) 360,000 entries in the reports table. So my query should return only 1000 records (for each employee the latest report for that month). How can i do this without using cursor?
thanks,
Dilip
3 888
Hi All,
I have a 2 tables namely Employee and reports. An employee will/can have multiple reports associated with him for a particular month. I need to fetch the the employee details and the last (or latest) report details for that month.
If for e.g Employee table has 100 entries, i will have (1000 * 12 month * 30 reports/month) 360,000 entries in the reports table. So my query should return only 1000 records (for each employee the latest report for that month). How can i do this without using cursor?
thanks,
Dilip
Join the tables and retrieve the records with the max. date, like this: -
select *
-
from employees e inner join reports r on e.empid=r.empid and r.repdate=(select max(repdate) from reports r2 where r2.empid=r.empid)
-
Join the tables and retrieve the records with the max. date, like this: -
select *
-
from employees e inner join reports r on e.empid=r.empid and r.repdate=(select max(repdate) from reports r2 where r2.empid=r.empid)
-
sorry i had reported it instead of replying...
thanks a lot for that reply...was very helpful and it only shows that i need to learn the basics . any idea where i can start from?
sorry i had reported it instead of replying...
thanks a lot for that reply...was very helpful and it only shows that i need to learn the basics . any idea where i can start from?
Not really, if you mean a certain book or URL. I suggest that you practice, look at what others do (look at the threads in this forum for example), check the docs (especially the help and not only what you need at a point but see other topics as well).
Others may be able to point you to some good sources as well.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Prem |
last post by:
Hi,
I am having many problems with inner join. my first problem is :
1) I want to know the precedance while evaluating query with multiple
joins.
eg.
select Employees.FirstName,...
|
by: nick |
last post by:
Hi,
I'm pretty much a database beginner and have what I think is a basic
question:
If I have a table which has a 'status' column and I can have say three
statuses: "active", "pending",...
|
by: jbm05 |
last post by:
Hi,
I'm curious about the computational complexity of a query I have. The
query contains multiple nested self left joins, starting with a simple
select, then doing a self left join with the...
|
by: michaelnewport |
last post by:
Greetings,
I like to write my inner joins as below,
but someone at work tells me its not as 'performant'
as using the 'inner join' statement.
Is this true ?
Is there a better way to write it...
|
by: Steve |
last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three
"Left Outer Joins" in order to return every transaction for a specific
set of criteria.
Using three "Left Outer Joins"...
|
by: Ryan McBride |
last post by:
Once again at my wonderful job i've been given the task of "come teach your
fellow idiot coworkers the skills you have"
I write software for a company in chicago. I use visual basic on asp.net...
|
by: MMcCarthy |
last post by:
To view Access queries in SQL rather than Access query design - open the query design window and change the view to SQL:
Select Statement
SELECT FROM ;
Append Statement
INSERT INTO (, , )...
|
by: walterbyrd |
last post by:
With PHP, libraries, apps, etc. to do basic CRUD are everywhere. Ajax
and non-Ajax solutions abound.
With Python, finding such library, or apps. seems to be much more
difficult to find.
I...
|
by: narendra vuradi |
last post by:
Hi I have a requirement where in i haev to convert the SQL from Oracle
to the one which will run on the SQL server.
in the Oracle Query i am doing multiple joins, between some 13 tables.
and...
|
by: TC |
last post by:
I've used Access for many years. Several times, I've encountered a bug
which I refer to as the "Vanishing Joins" bug. When it happens, joins
vanish randomly from queries. More specifically, all...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |