seran128 Posted October 29, 2006 Share Posted October 29, 2006 I have a table that looks like thistbl_productID Cost1 5.232 3.767 25.22now I want to run a query that returns the value of the difference between two product id'slikepsudeo code finalcost = (select cost from tbl_products where id = '1') - (select cost from tbl_products where id = '2')in this case finalcost should be 1.47Is there a way to do this in one SQL statment Link to comment https://forums.phpfreaks.com/topic/25455-finding-the-diference-between-two-values/ Share on other sites More sharing options...
Barand Posted October 29, 2006 Share Posted October 29, 2006 SELECT a.price - b.price as diffFROM prices a JOIN prices bON a.price_id = 1 AND b.price_id = 2 Link to comment https://forums.phpfreaks.com/topic/25455-finding-the-diference-between-two-values/#findComment-116193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.