>>select distinct rep, .t. as SA_flag from myTable ; where pub = "SA" ;union ;
>select distinct rep, .f. as SA_flag from myTable ;
> where rep not in (select distinct rep from myTable where pub="SA") ;order by 1
>
>Assuming a significant size "myTable", how would that statement compare with:
>Select distinct rep, .t. as SA_Flag from myTable where pub="SA";
>union;
>Select distinct rep, .f. as SA_Flag from myTable where NOT (pub="SA")
>
>It seems the first statement would be querying the same set twice.
>
>I thought there was an "in-line" way to get a unique value from a group, but i guess the two-step union will work (almost) as effectively.
Michael,
I thought it but I think it won't work. Why, because there could be records with pub # "SA" with same rep those having pub="SA". Union wouldn't handle it becuse of the unmatching SA_Flag.
rep pub
--- ---
1
1 SA
1
2
3
4 SA
4
5
5 SA
rep SA_Flag
--- ---
1 .T.
1 .F.
2 .F.
3 .F.
4 .T.
4 .F.
5 .T.
5 .F.
For performance and one pass there could be other clever SQLs :) Like :
Select rep, iif(sum(iif(pub="SA",1,0))>0,.t.,.f.) as SA_Flag ;
from myTable ;
group by 1
Cetin