Select Distinct with Multiple Columns SQL Server - TechRepublic
Question
February 18, 2010 at 01:27 PM
meengla

Select Distinct with Multiple Columns SQL Server

by meengla . Updated 16 years, 4 months ago

Hi,
I have a SQL Server 2005 database in which 3 tables are joined together by prodid field.
Here is a query which gets me close but not quite close enough. In this query the Product Name (from the Products table) shows up 4 times IF there are 4 options related to that Product. May be that’s inevitable as far as query is concerned but how can I then show the Product name only once on a page (it is ColdFusion) if there are 4 options while still showing the product only once if there is only 1 option (the default option of ‘na’ in the Products_options table.
Thanks!
—————————-
SELECT
dbo.products.prodid,
dbo.products.name,
dbo.products.description,
dbo.products.image,
dbo.products_options.optionname,
dbo.products_options.price,
dbo.products_options.optionid
FROM
dbo.products_featured
INNER JOIN dbo.products ON (dbo.products_featured.prodid = dbo.products.prodid)
INNER JOIN dbo.products_options ON (dbo.products.prodid = dbo.products_options.prodid)

This discussion is locked

All Comments