I need to retrieve randomly 4 products from a table, let's call it tblProducts, where I am storing products some are "Special Offer" and some are not. The trick is if I do not have 4 products with I need to retrieve the difference from products not in offer. I tried to go with Union but it didn't work. What I am execting is to retrieve something like shown below, I should ALWAY retrieve "Product 1", "Product 6" and "Product 7" as they are the only ones in offer and one other product to complete the 4 products I need. "Product 6""Product 2""Product 1""Product 7"The next run"Product 7""Product 1""Product 3""Product 6"Or the next"Product 10""Product 7""Product 6""Product 1"Or the next"Product 1""Product 11""Product 6""Product 7"Etc...CREATE TABLE [dbo].[tblProducts]( [P_Id] [int] IDENTITY(1,1) NOT NULL, [P_Special] [int] NOT NULL, [P_Text] [nvarchar](50) NOT NULL) ON [PRIMARY]INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (1, 'Product 1')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (0, 'Product 2')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (0, 'Product 3')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (0, 'Product 4')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (0, 'Product 5')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (1, 'Product 6')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (1, 'Product 7')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (0, 'Product 8')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (0, 'Product 9')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (0, 'Product 10')INSERT INTO [tblProducts]([P_Special],[P_Text]) VALUES (0, 'Product 11')
jean-lucwww.corobori.com