473,386 Members | 1,736 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,386 software developers and data experts.

Completely flustered with a Latest Date from Subset problem.

Someone should write a FAQ on how to grab various "latest dates" from MySQL; cuz I'm quite confused.

Not sure how much to include; but here' my query to get my first "subset" of data:
select caseResults.* from caseResults, runs, scriptResults where runs.runID = scriptResults.runID and runs.runID in (476,477,479,480) and scriptResults.scriptResultID = caseResults.scriptResultID order by caseResults.caseID
This will return; for example a dataset of:

Expand|Select|Wrap|Line Numbers
  1. +--------------+----------------+--------+--------------+-----------+---------------------+-------------------+-----------------+
  2. | caseResultID | scriptResultID | caseID | caseStatusID | published | startedCase         | caseExecutionTime | caseRunComments |
  3. +--------------+----------------+--------+--------------+-----------+---------------------+-------------------+-----------------+
  4. |        30462 |           9913 |      6 |            1 |         0 | 2007-04-02 07:56:46 |                 3 | NULL            | 
  5. |        30467 |           9913 |      7 |            1 |         0 | 2007-04-02 07:56:59 |                 2 | NULL            | 
  6. |        30014 |           9773 |      8 |            1 |         0 | 2007-04-02 06:12:19 |                 9 | NULL            | 
  7. |        30025 |           9776 |      8 |            1 |         0 | 2007-04-02 06:12:59 |                 7 | NULL            | 
  8. |        30029 |           9777 |      8 |            1 |         0 | 2007-04-02 06:13:37 |                 7 | NULL            | 
  9. |        30047 |           9783 |      8 |            1 |         0 | 2007-04-02 06:16:08 |                12 | NULL            | 
  10. |        30050 |           9784 |      8 |            1 |         0 | 2007-04-02 06:16:51 |                11 | NULL            | 
  11. |        30055 |           9785 |      8 |            1 |         0 | 2007-04-02 06:17:34 |                11 | NULL            | 
  12. |        30017 |           9773 |      9 |            1 |         0 | 2007-04-02 06:12:29 |                24 | NULL            | 
  13. |        30048 |           9783 |      9 |            1 |         0 | 2007-04-02 06:16:21 |                24 | NULL            | 
  14. |        30023 |           9773 |     10 |            1 |         0 | 2007-04-02 06:12:53 |                 4 | NULL            | 
  15. ......snip....
All told, lets say 500 records (i won't include them all for brevities sake).

Now, for each unique caseID (6, 7, 8..., 9, etc.) i want to return the latest caseResultsID as dictated by the startedCase date. So for instance, in the above data, for caseID 8 i'd want to have it return 30055.

I have been wrestling with this for a few days now, trying various joins, or sub-selects, or whatnot. And a) i'm not sure i understand how to use joins properly when you are using so many tables in the first place, and b) when I finally got something I thought would work (and it did) it was PAINFULLY and exponentially slow.

I could also do it per caseID (ie; a independent query for each unique caseID) but that seems like a bad design, and it would shove much at the database.

I fully understand that the original sub-select is returning more info that I really need; i'm just did that (for now) so that I could determine if my selects where returning the rows I was expecting.

At this point, I'm not even sure what to attempt anymore. Any help would be a godsend.

---c
May 2 '07 #1
1 1280
code green
1,726 Expert 1GB
You haven't shown your tables design. So your query is hard to follow. I will make a stab and suggest you should have at least three tables. One to list the cases with IDs. One for the results with IDs. And the third correlates the IDs. This is a many to many design. It sounds like you are trying to do it with two tables.
May 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
2
by: Andy Fish | last post by:
Hi, I have an application with a vb6 client that talks to a java server and passes XML back and forward, and I'm wondering what's the best format to transfer date/time values between them in an...
2
by: M.Stanley | last post by:
Hi, I have a problem..I'm doing a specific query where I'm joining fields from a table with appednded data (there are duplicate records, except for the date/time), and another query. I want the...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
8
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as...
7
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...
76
by: kwilder | last post by:
This works, but it doesn't load the latest version of the xml if it was just modified without closing and reopening the browser. Here's the scenario: I have an xml doc called results.xml. It...
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...
7
by: Eugene | last post by:
Hi all, I have the following table Name Date Wish Valid Name is person's name, date defaults to getdate() and is never assigned directly (datetime field), Wish is some message, and...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
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...

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.