473,796 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I'm stuck searching for a query

Hi !

I've got a problem trying to figure out a query.

I have a table with following fields:

tool varchar(30)
last_date datetime
user_id mediumint(8)
....

example:

tool last_date

1 mail 2004-09-05 12:11:44
2 mail 2004-09-01 11:33:12
3 agenda 2004-09-06 17:34:55
4 export 2004-09-02 14:33:16
5 agenda 2004-08-30 19:55:32
6 mail 2004-09-07 14:13:12
7 agenda 2004-09-02 09:54:35

Now i'm trying to creat a query that gives me the tools who were last changed.

this should give:

6 mail 2004-09-07 14:13:12
3 agenda 2004-09-06 17:34:55
4 export 2004-09-02 14:33:16

If anyone can help me with this query, it would be greatly appreciated.

Thanx.
Jul 20 '05 #1
2 1414
Select * From tblname Order By last_date

Patrick

sc**********@ho tmail.com (Olivier) wrote in message news:<ac******* *************** ****@posting.go ogle.com>...
Hi !

I've got a problem trying to figure out a query.

I have a table with following fields:

tool varchar(30)
last_date datetime
user_id mediumint(8)
...

example:

tool last_date

1 mail 2004-09-05 12:11:44
2 mail 2004-09-01 11:33:12
3 agenda 2004-09-06 17:34:55
4 export 2004-09-02 14:33:16
5 agenda 2004-08-30 19:55:32
6 mail 2004-09-07 14:13:12
7 agenda 2004-09-02 09:54:35

Now i'm trying to creat a query that gives me the tools who were last changed.

this should give:

6 mail 2004-09-07 14:13:12
3 agenda 2004-09-06 17:34:55
4 export 2004-09-02 14:33:16

If anyone can help me with this query, it would be greatly appreciated.

Thanx.

Jul 20 '05 #2
> Now i'm trying to creat a query that gives me the tools who were last changed.

This is one of those types of problem queries that folks post regularly
to this newsgroup: how does one output a group-invariant value _and_
row-specific values in one query?

One method is to use subqueries:

select t1.user_id, t1.tool, t1.last_date
from myTable t1 inner join
(select tool, max(last_date) as max_last_date
from myTable group by tool) t2
on t1.tool = t2.tool and t1.last_date = t2.max_last_dat e

Note that subqueries require MySQL 4.1. This example won't work in
MySQL 4.0 or earlier.

Another method is to fetch all the rows with a simpler query, and
calculate the max date in your application code. For example, in
Perl/DBI this might be:

my $st = $dbh->prepare('selec t user_id, tool, last_date from myTable
order by last_date');
$st->execute();
my $result_set = $st->fetchall_array ref({});
my %tool_hash = ();
for my $row (@$result_set)
{
$tool_hash{ $row->{tool} } = {
user_id => $row->{user_id},
last_date => $row->{last_date}
};
}

This overwrites the hash list entry for each tool as it iterates through
the result set, and since the query was ordered by last_date, it should
naturally produce a final %tool_hash containing the most recent values
per tool.

Note these code examples are untested.

Regards,
Bill Karwin
Jul 20 '05 #3

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

Similar topics

4
1641
by: donald | last post by:
Hi all, I have a website running asp (about to move to asp.net soon though) which has a list of DVD's I have the various pages I want, last 10, listing, full listing ect, but the one page i can't figure out is a search page. I have read various books, but none have given any tips on how to make a search page for a access DB. Could someone point me to a tutorial? Thanks
3
1481
by: aaj | last post by:
This is a simple question compared to some of the stuff that gets asked (and answered) here, but sometimes its easy to over look the simpler things. I've been working with databases for a few years now, but have no formal training, so some times you just get on and if it works dont worry about it. But sometimes I wonder just how it works underneath the skin e.g. If I have 100000 records in a complicated view and say each record, amongst...
2
1427
by: Alex A via .NET 247 | last post by:
Hello all. I'm new to .NET and I am stuck and I just cannot getthis to work (even after much searching). I have a listbox populated by data from an Access Database. Themanner in which I fill the listbox is as follows: \\\\\\\\ dsClosedPos.Clear() dbAdapter.SelectCommand = New OleDbCommand dbAdapter.SelectCommand.Connection = dbConnect dbAdapter.SelectCommand.CommandText = _
3
1945
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store objects of my classes Person(superclass), Student(inherit Person), Teacher(inherit Person) in that array. The name will be the unique key. These classes are all working ok. I want to be able to add, remove, find etc. objects. To all of this, I...
1
2426
by: Robert Oschler | last post by:
I read a while back that MySQL will only use one index per query. (If this is not so, please tell me and point me to a doc that gives a good explanation of MySQL's current index usage policy). I'm using MySQL 4.2.x. Here's my dilemma. 1) --------- I have two tables that have records with a FULLTEXT index text field in each of them. The problem is the relationship between the tables is a
4
1436
by: Jordan S. | last post by:
Using .NET 2.0 (C#) I'm writing a small app that will have a "Person" class that exposes FirstName and LastName properties. At runtime, a "People" collection will be populated with a few thousand "Person" objects. I want to provide users with the ability to search for people by FirstName and/or LastName. My question: How can I enable users to search for people with the last name of "De Leon". I cannot assume that my users know how to...
1
2368
by: colleen1980 | last post by:
When I run my query it stuck is it possible that i can debug it SELECT TOP 1 tblCredits.OPR, Min(tbl_CRCDollars.SumOfAMOUNT) AS MinOfSumOfAMOUNT, Avg(tblCredits.Credit) AS AvgOfCredit, Count(tblCredits.OPR) AS CountOfOPR1, tbl_WorkingCountDays.CountOfREPORT_DATE, (!)/(!) AS AvgNum INTO tbl_TopRep FROM tbl_CRCDollars, qry_TopDollarAvgDays, tbl_WorkingCountDays, tblCredits
8
1876
by: Allan Ebdrup | last post by:
What would be the fastest way to search 18,000 strings of an average size of 10Kb, I can have all the strings in memory, should I simply do a instr on all of the strings? Or is there a faster way? I would like to have a kind of search like google where you can enter several words to search for, guess that calls for a regular expression "word1|word2|word3|...". Is there any kind of indexing tools available for this kind of thing, I have my...
3
3290
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a "Searching..." page then, refreshes and displays the table I want. I have code that grabs data from the page using cURL but when I look at the data it contains the "Searching..." page and not the table that I want. below is the code i have so far....Thanks...
0
9685
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
10239
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
10190
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
10019
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
9057
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
7555
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...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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

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.