MySQL Forums
Forum List  »  Newbie

Fastes way to do this
Posted by: Roberto Cano Ramos
Date: August 11, 2005 08:17AM

Hi,
I need to do the following the fastest way possible:

let say I have 2 tables T1 and T2


Example data for T1
--------------------------------
id|ok |mark | id_t2 | date
--------------------------------
1|true | 0 | 1 | 01/01/05
2|true | 0 | 1 | 05/01/05
3|true | 0 | 2 | 01/01/05
4|false| 0 | 1 | 02/01/05
5|true | 0 | 1 | 03/01/05
6|true | 0 | 1 | 04/01/05

Example data for T2
------
id| m
------
1| 3
2| 7

t2.m link to t1.id_t2

T2.m indicate the number of the row in t1 that has to be set field "mark" to 1 not counting the ones that have t1.ok=false order by t1.date then rest all get mark to 0

Here is the result that I need set for a query where t2.id=1

id|ok |mark | id_t2 | date
--------------------------------
1|true | 0 | 1 | 01/01/05 * row 1
4|false| 0 | 1 | 02/01/05 * does not count ok=false
5|true | 0 | 1 | 03/01/05 * row 2
6|true | 1 | 1 | 04/01/05 * row 3 this one equal t2.m
2|true | 0 | 1 | 05/01/05 * row 4

Hope that you understand it...

Thanks

Roberto

Options: ReplyQuote


Subject
Written By
Posted
Fastes way to do this
August 11, 2005 08:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.