Hi,
I have created an MS Access database containing the following tables:
Crime
CrimeCommitted
Criminal
CriminalOrganiz ation
CriminalType
HideoutType
The Criminal table is the parent table that contains a one-to-many relationship with the CrimeCommitted Table (a criminal can commit many crimes). I've sorted the CrimeCommitted table in descending Date (that the crime was committed) so that the latest crime is at the top of the table.
What i need to do is to write a query to select only the lastest crime committed by a criminal. Then i will be retrieving this database from a Crystal Report to view the lastest crime for each criminal. I've tried using the SELECT DISTINCT statement
SELECT DISTINCT CriminalID FROM CrimeCommitted
and it returns each CriminalID once. But how can i write a query to retrieve only the lastest crime for each criminal?
3 2929 ADezii 8,834
Recognized Expert Expert
Hi,
I have created an MS Access database containing the following tables:
Crime
CrimeCommitted
Criminal
CriminalOrganiz ation
CriminalType
HideoutType
The Criminal table is the parent table that contains a one-to-many relationship with the CrimeCommitted Table (a criminal can commit many crimes). I've sorted the CrimeCommitted table in descending Date (that the crime was committed) so that the latest crime is at the top of the table.
What i need to do is to write a query to select only the lastest crime committed by a criminal. Then i will be retrieving this database from a Crystal Report to view the lastest crime for each criminal. I've tried using the SELECT DISTINCT statement
SELECT DISTINCT CriminalID FROM CrimeCommitted
and it returns each CriminalID once. But how can i write a query to retrieve only the lastest crime for each criminal?
- SELECT Criminal.CriminalID, Criminal.Name, Max(CrimeCommitted.Date) AS Last_Crime_Committed
-
FROM Criminal INNER JOIN CrimeCommitted ON Criminal.CriminalID = CrimeCommitted.CriminalID
-
GROUP BY Criminal.CriminalID, Criminal.Name;
- SELECT Criminal.CriminalID, Criminal.Name, Max(CrimeCommitted.Date) AS Last_Crime_Committed
-
FROM Criminal INNER JOIN CrimeCommitted ON Criminal.CriminalID = CrimeCommitted.CriminalID
-
GROUP BY Criminal.CriminalID, Criminal.Name;
Thanks for your reply ADezii!
ADezii 8,834
Recognized Expert Expert
Thanks for your reply ADezii!
Glad I could help you, Penny111.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: netpurpose |
last post by:
I need to extract data from this table to find the lowest prices of
each product as of today. The product will be listed/grouped by the
name only, discarding the product code - I use SUBSTRING(ProductName,
1, CHARINDEX('(', ProductName)-2).
I can get this result, but I had to use several views (totally
inefficient). I think this can be done in one efficient/fast query,
but I can't think of one.
In the case that one query is not...
|
by: Dom |
last post by:
I need to run a query based on a query in Access. The second query has
a number of conditions which all work well, but there is one more
contition I need to set to make it run properly.
the first query returns a number of data items, consisting, among other
fields, of a Company_ID and a Rating_Date. For most companies, the
latest value of Rating_Date is equal to a value in a seperate table
(tblVariables) which logs the last time a...
|
by: Larry R Harrison Jr |
last post by:
I have a database I'm designing in Access 97. I have a custom field in a
query which looks in {Table of Documents} and shows them all. It then needs
a "latest revision number," stored in another table named {Table of
Revisions}. It naturally matches them up by linking the autoid in {Doc} with
the related field in {Rev}. It then looks for a field in {Rev} called
"revision number" and looks for the last one for the given Doc (linked by
the...
|
by: Scott Frankel |
last post by:
Still too new to SQL to have run across this yet ...
How does one return the latest row from a table, given multiple entries
of varying data?
i.e.: given a table that looks like this:
color | date
--------+------------
red | 2004-01-19
blue | 2004-05-24
|
by: serge |
last post by:
How can I run a single SP by asking multiple sales question either
by using the logical operator AND for all the questions; or using
the logical operator OR for all the questions. So it's always
either AND or OR but never mixed together.
We can use Northwind database for my question, it is very similar
to the structure of the problem on the database I am working on.
IF(SELECT OBJECT_ID('REPORT')) IS NOT NULL
DROP TABLE REPORT_SELECTION
| |
by: clare at snyder.on.ca |
last post by:
I have a SQL query I need to design to select name and email addresses
for policies that are due and not renewed in a given time period. The
problem is, the database keeps the information for every renewal in
the history of the policyholder.
The information is in 2 tables, policy and customer, which share the
custid data. The polno changes with every renewal Renewals in 2004
would be D, 2005 S, and 2006 L. polexpdates for a given customer...
|
by: jim |
last post by:
I am working on a database to save information about jobs i have to
complete and which parts of jobs must be completed by what dates
I have two tables Jobs(primary key JobID) which is linked via a one-many
relationship with a JobParts table(primary key PartID, foreign key JobID)
I want to list just the next part of each particular job which is due to
be completed so from my JobParts table below:
PartID CompleteBy JobID
|
by: Jordan M. |
last post by:
Hi,
Hoping to get some help modifying the following query that I have...
TABLE: NAMES
ID, FirstName, LastName
TABLE: EMAILS
ID,LinkID,Email,LastUpdateDate
|
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...
|
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...
|
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...
| |
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |