Friday 15 March 2013

sql - Trouble understanding the output involving Distinct -



sql - Trouble understanding the output involving Distinct -

i'm struggling understand why these 2 statements giving same output:

case 1:

select sum(distinct prod_price) products

case 2:

select sum(sq.cost) (select distinct [vend_id] prod,[prod_price] cost products) sq

where output select * products looks like:

think query

select sum(sq.cost) (select distinct [vend_id] prod,[prod_price] cost products) sq

as

select distinct [vend_id] prod,[prod_price] cost products

going temp table named sq 2 columns:

vend_id prod_price

this query going evaluated first , next part of query like:

select sum(sq.cost) sq

which nil same original query , hence same answer.

sql

No comments:

Post a Comment