Hi, Thanks for your reply but it is not giving proper results. I given table structure and sample data below and output required too.CREATE TABLE [dbo].[carttable]( [cartid] [int] IDENTITY(1,1) NOT NULL, [customerid] [int] NULL, [productid] [int] NULL, CONSTRAINT [PK_carttable] PRIMARY KEY CLUSTERED ( [cartid] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]---------------------CREATE TABLE [dbo].[groups]( [groupid] [int] IDENTITY(1,1) NOT NULL, [groupname] [varchar](50) NULL, [groupamount] [money] NULL, CONSTRAINT [PK_groups] PRIMARY KEY CLUSTERED ( [groupid] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]---------------------CREATE TABLE [dbo].[groupproducts]( [groupproductid] [int] IDENTITY(1,1) NOT NULL, [groupid] [int] NULL, [productid] [int] NULL, CONSTRAINT [PK_groupproducts] PRIMARY KEY CLUSTERED ( [groupproductid] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]----------------------- INSERT SCRIPTSET IDENTITY_INSERT [dbo].[carttable] ON;BEGIN TRANSACTION;INSERT INTO [dbo].[carttable]([cartid], [customerid], [productid])SELECT 1, 1, 1 UNION ALLSELECT 2, 1, 2 UNION ALLSELECT 3, 1, 3COMMIT;GOSET IDENTITY_INSERT [dbo].[carttable] OFF;-------------------SET IDENTITY_INSERT [dbo].[groups] ON;BEGIN TRANSACTION;INSERT INTO [dbo].[groups]([groupid], [groupname], [groupamount])SELECT 1, N'grp1', 152.0000 UNION ALLSELECT 2, N'grp2', 554.0000 UNION ALLSELECT 3, N'grp3', 33.0000COMMIT;RAISERROR (N'[dbo].[groups]: Insert Batch: 1.....Done!', 10, 1) WITH NOWAIT;GOSET IDENTITY_INSERT [dbo].[groups] OFF;---------------------SET IDENTITY_INSERT [dbo].[groupproducts] ON;BEGIN TRANSACTION;INSERT INTO [dbo].[groupproducts]([groupproductid], [groupid], [productid])SELECT 1, 1, 1 UNION ALLSELECT 2, 1, 2 UNION ALLSELECT 3, 2, 3 UNION ALLSELECT 4, 2, 2 UNION ALLSELECT 5, 3, 1 UNION ALLSELECT 6, 3, 4COMMIT;GOSET IDENTITY_INSERT [dbo].[groupproducts] OFF;-----------------
Above data have 3 groups and shopping cart table contains 3 record applicable to group 1..group 1 consists 2 products which matches shopping cart products than other group products.* so group 1 only should return with its amount.thanks