Jump to content

sql query


alin19

Recommended Posts

i'm trying to use this query: SELECT * FROM `op_tranzactionare`  GROUP BY `id_bo` to get the last record for each id_bo

 

by i get the first record for each one, what can i do?

     

 

        id_bo

se28  2008-03-22  SIF1  SELL  2.7000  1000  0.50  0.00

FL15 2008-03-22 SIF1 BUY 99.9999 12 9.99 0.00

FL15 2008-03-22 SIF1 SELL 0.0000 0 0.00 0.00

FL15 2008-03-22 BRD SELL 18.5000 1000 0.50 18607.30

FL15 2008-03-22 SIF1 BUY 0.0000 0 0.00 0.00

FL15 2008-03-22 SIF1 SELL 0.0000 0 0.00 0.00

FL15 2008-03-23 SIF1 SELL 0.0000 0 0.00 0.00

MM36 2008-03-22 TLV BUY 1000.0000 0 1.00 594.00

yu21 2008-03-22 TLV BUY 1000.0000 2000 1.00 1980000.00

yu21 2008-03-22 SIF3 SELL 1.6000 11111 1.00 17969.60

Link to comment
https://forums.phpfreaks.com/topic/97517-sql-query/
Share on other sites

there is another colum colled id autoincremented

 

I don't quite understand the question, but from what I can get, your best bet is using

ORDER BY id DESC

and if you just want the last result

ORDER BY id DESC LIMIT 1

 

I can't guarentee it'll work, but try:

SELECT * FROM `op_tranzactionare`  GROUP BY `id_bo` ORDER BY id DESC

Link to comment
https://forums.phpfreaks.com/topic/97517-sql-query/#findComment-498956
Share on other sites

i've tryed that already, doesnt work

from this:

1 se28 2008-03-22 SIF1 SELL 2.7000 1000 0.50 0.00

2 FL15 2008-03-22 SIF1 BUY 99.9999 12 9.99 0.00

3 FL15 2008-03-22 SIF1 SELL 0.0000 0 0.00 0.00

4 FL15 2008-03-22 BRD SELL 18.5000 1000 0.50 18607.30

5 FL15 2008-03-22 SIF1 BUY 0.0000 0 0.00 0.00

6 FL15 2008-03-22 SIF1 SELL 0.0000 0 0.00 0.00

7 FL15 2008-03-23 SIF1 SELL 0.0000 0 0.00 0.00

8 MM36 2008-03-22 TLV BUY 1000.0000 0 1.00 594.00

9 yu21 2008-03-22 TLV BUY 1000.0000 2000 1.00 1980000.00

10 yu21 2008-03-22 SIF3 SELL 1.6000 11111 1.00 17969.60

 

i get this:

 

9  yu21  2008-03-22  TLV  BUY  1000.0000  2000  1.00  1980000.00

8 MM36 2008-03-22 TLV BUY 1000.0000 0 1.00 594.00

2 FL15 2008-03-22 SIF1 BUY 99.9999 12 9.99 0.00

1 se28 2008-03-22 SIF1 SELL 2.7000 1000 0.50 0.00

 

i need to ghet id 7 instead of 2, because that is the last one for se28, and 10 instead of 9 for yu21

Link to comment
https://forums.phpfreaks.com/topic/97517-sql-query/#findComment-498959
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.