![]() | |
#1
| |||
| |||
|
|
id | ...some data fields... | |
|
id | users_id | ...some data fields... | timestamp | |
#2
| |||
| |||
|
|
Dear all, I have a question about a query I would improve (I know it is not the best). I have two tables: USER: | id | ...some data fields... | DATA: | id | users_id | ...some data fields... | timestamp | I think they are quiet self explaining. When a user update something, instead of update the related record, he insert a new one (this is for keeping track of the changes). Now, if I want to extract the _last record for each user_ I select all the users firstly (there are no duplicates in USER table) and, then, for each user I select the corresponding data records, sorted by descending timestamping: the first of the returning set is the desired one. So, if I have n users, I need n+1 queries. How to improve that (no subqueries, I'm stuck with MySql 4)? Thank you Libra |
#3
| |||
| |||
|
|
When a user update something, instead of update the related record, he insert a new one (this is for keeping track of the changes). |
|
(no subqueries, I'm stuck with MySql 4) |
#4
| |||
| |||
|
|
(no subqueries, I'm stuck with MySql 4) Given that MySQL is a free product, I am curious what the hindrance is to an upgrade. |
#5
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |