alin19 Posted March 24, 2008 Share Posted March 24, 2008 select * from (select id_port, id_bo, simbol, volum from `portofolii` where id_bo='se28' order by `id_port` desc) group by `id_port` what i have wrong in this query? here: ( select id_port, id_bo, simbol, volum from `portofolii` where id_bo='se28' order by `id_port` desc) i try order desc all my database and there group by simbol, Link to comment https://forums.phpfreaks.com/topic/97664-sql-query-error/ Share on other sites More sharing options...
BlueSkyIS Posted March 24, 2008 Share Posted March 24, 2008 select id_bo, simbol, volum from `portofolii` where id_bo='se28' order by `id_port` desc, `simbol` asc Link to comment https://forums.phpfreaks.com/topic/97664-sql-query-error/#findComment-499708 Share on other sites More sharing options...
alin19 Posted March 24, 2008 Author Share Posted March 24, 2008 yes this works, but just turns my database upside down now i need to make something like this: select * from (select id_port,id_bo, simbol, volum from `portofolii` where id_bo='se28' order by `id_port` desc, `simbol` asc) group by `simbol` to select from this query, but i get this error: #1248 - Every derived table must have its own alias Link to comment https://forums.phpfreaks.com/topic/97664-sql-query-error/#findComment-499713 Share on other sites More sharing options...
BlueSkyIS Posted March 24, 2008 Share Posted March 24, 2008 there is no need for a sub-select, but i don't think you'll get the results you expect: select id_port,id_bo, simbol, volum from `portofolii` where id_bo='se28' group by A.simbol order by `id_port` desc, `simbol` asc Link to comment https://forums.phpfreaks.com/topic/97664-sql-query-error/#findComment-499718 Share on other sites More sharing options...
alin19 Posted March 24, 2008 Author Share Posted March 24, 2008 this turn the same as select * from `portofolii` order by `simbol` returns the first record for each simbol, i need to get the last record for each simbol, so i thougth to turn the database upside down and then search to get the last record instead of first Link to comment https://forums.phpfreaks.com/topic/97664-sql-query-error/#findComment-499725 Share on other sites More sharing options...
alin19 Posted March 24, 2008 Author Share Posted March 24, 2008 SELECT sum_column1, test2, test3 FROM (SELECT id_port AS sum_column1, id_bo AS test2, simbol AS test3 FROM portofolii ORDER BY `id_port` DESC ) AS table GROUP BY test2 this seams to work; 10x Link to comment https://forums.phpfreaks.com/topic/97664-sql-query-error/#findComment-499781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.