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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.