all groups > sql server programming > january 2006 >
You're in the

sql server programming

group:

union ?


Re: union ? Jens
1/20/2006 12:43:38 PM
sql server programming:
If it isn=B4t possible to set the flag for individual customers, you can
only query for the CustomerGroups, right ? If there is something like a
Xref table the query should be something like this:

Select <columnlist>
FROM
Customer C
INNER JOIN CustomerCustomerGroupXref CX
ON C.CustomerId =3D CX.CustomerId
INNER JOIN CustomerGroup CG
ON CG.GroupId =3D CX.GroupId
Where CG.vip_flag =3D 1

Am I right ?

HTH, Jens Suessmeyer.
Re: union ? Jim Underwood
1/20/2006 3:50:36 PM
I see nothing at all wrong with your original approach, but if you want an
alternative, how about using exists?

select id, code from customers
where vip_flag = 1
or exists (select ... from customers join CustomerGroup
... where CustomerGroup.vip_flag = 1
AND CustomerGroup.CustomerID = Customer.CustomerID
)


[quoted text, click to view]

union ? Fred
1/20/2006 10:35:10 PM
hi, i have tables Customer, CustomerGroup and CustomerCustomerGroupXref
( :) ), now i want to find customers having say vip_flag, only that flag
can be set for whole gropus and the indivdual customers inside group
wont than have it set

curenty i do

select id, code from customers
where vip_flag = 1

union

select ... from customers join CustomerGroup
.... where CustomerGroup.vip_flag = 1

but there must be a better way ...

AddThis Social Bookmark Button