alin19 Posted March 23, 2008 Share Posted March 23, 2008 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 More sharing options...
Barand Posted March 23, 2008 Share Posted March 23, 2008 As they all have the same date and no time there doesn't appear to be a way of identifying the "last" Link to comment https://forums.phpfreaks.com/topic/97517-sql-query/#findComment-498952 Share on other sites More sharing options...
alin19 Posted March 23, 2008 Author Share Posted March 23, 2008 there is another colum colled id autoincremented Link to comment https://forums.phpfreaks.com/topic/97517-sql-query/#findComment-498954 Share on other sites More sharing options...
Bladescope Posted March 23, 2008 Share Posted March 23, 2008 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 More sharing options...
alin19 Posted March 23, 2008 Author Share Posted March 23, 2008 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 More sharing options...
alin19 Posted March 23, 2008 Author Share Posted March 23, 2008 can't you help me? Link to comment https://forums.phpfreaks.com/topic/97517-sql-query/#findComment-498985 Share on other sites More sharing options...
Barand Posted March 23, 2008 Share Posted March 23, 2008 SELECT o.* FROM `op_tranzactionare` o INNER JOIN (SELECT id_bo, MAX(id) as last FROM `op_tranzactionare`GROUP BY id_bo) as x ON o.id_bo = x.id_bo AND o.id = x.last Link to comment https://forums.phpfreaks.com/topic/97517-sql-query/#findComment-499054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.