473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Query latest record

Hi All,

I need some help with a query.
Here is the structure for the table:
ID, sDate, sComment, sRole

Possible values in the table:
0101, 11/6/2006, Comment123, Role1
0101, 11/6/2006, Comment124, Role1
0101, 11/6/2006, Comment125, Role2
0101, 11/6/2006, Comment126, Role2

As you see, ID is not a primary key.
We would like the query to return the latest Comment for each ID and
sRole.

eg. if we pass ID=0101 and sRole = Role1, we would like the query to
return Comment124, based upon the timestamp (though the date is same,
the time is later for that record.

Any suggestions?

Thanks,
Paul

Nov 7 '06 #1
1 1598
ac*******@gmail.com wrote:
Hi All,

I need some help with a query.
Here is the structure for the table:
ID, sDate, sComment, sRole

Possible values in the table:
0101, 11/6/2006, Comment123, Role1
0101, 11/6/2006, Comment124, Role1
0101, 11/6/2006, Comment125, Role2
0101, 11/6/2006, Comment126, Role2

As you see, ID is not a primary key.
We would like the query to return the latest Comment for each ID and
sRole.

eg. if we pass ID=0101 and sRole = Role1, we would like the query to
return Comment124, based upon the timestamp (though the date is same,
the time is later for that record.

Any suggestions?

Thanks,
Paul
Untested SQL:

SELECT TOP 1 sComment
FROM tblPaul
WHERE ID = '0101'
AND sRole = 'Role1'
ORDER BY sDate DESC;

--
Smartin
Nov 7 '06 #2

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

Similar topics

1
by: Dino Nardini | last post by:
Hey folks, I've been migrating a content management system from MS SQL Server 7 over to PostgreSQL. I used the EMS DataPump utility (http://www.ems-hitech.com/index.phtml) to migrate the...
6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
1
by: dixie | last post by:
If I have a query that returns say, 3 records sorted by date, so that the latest record is at the bottom of the list, can I then use just the information from that last record to put onto an...
2
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...
1
by: travismorien | last post by:
I have four tables of different "entities". One table contains information for "people", one for "trusts", one for "companies" and one for "self managed super funds". Each type of entity has an...
5
by: alanspamenglefield | last post by:
Hello group, I have an SQL statement which pulls data from a table as follows: " SELECT tblSites.sites_siteno, " & _ " tblSites.sites_sitename, " & _ " Sum(tblStockResults.stkr_result) AS...
4
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...
1
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
1
by: jrpfinch | last post by:
Hi I am relatively new to databases. I would like to be able to run a query that returns the t_no, b_no, status and cpu for the latest record for each unique combination of (t_no, b_no and cpu)...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...

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.