SQL CODE

I have a table that I need to return all columns but ONLY the ones with a DISTINCT value in one of the columns.

This code retrns 340 rows but 12 are duplicates ( product_desc)
select bev_type,franchisor,super_brand,brand,product_code,product_desc,super_package,package,
eq_eaches,eq_converted,eq_twelve_oz,eq_fountain,eq_sellunit from dbo.product
where product_desc like 'BIBPST%'
order by product_desc

how would I change it to ONLY show me the ones with distinct prduct_desc?
craigs052998Asked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
select bev_type,franchisor,super_brand,brand,MAX(product_code)product_code,  Product_Desc,super_package,package,
eq_eaches,eq_converted,eq_twelve_oz,eq_fountain,eq_sellunit
 from dbo.product
where product_desc like 'BIBPST%'
GROUP BY bev_type,franchisor,super_brand,brand,Product_Desc,super_package,package,eq_eaches,eq_converted,eq_twelve_oz,eq_fountain,eq_sellunit
0
 
SQL_SERVER_DBACommented:
select DISTINCT product_desc, bev_type,franchisor,super_brand,brand,product_code,super_package,package,
eq_eaches,eq_converted,eq_twelve_oz,eq_fountain,eq_sellunit from dbo.product
where product_desc like 'BIBPST%'
order by product_desc
0
 
craigs052998Author Commented:
I forgot to mention there are some columns with differnt items because when the data was loaded they did not check for that product already.  The issues I have is 1 product description with 3 product codes or some other value of some column
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Aneesh RetnakaranDatabase AdministratorCommented:
select bev_type,franchisor,super_brand,brand,product_code,MIN(product_desc) Product_Desc,super_package,package,
eq_eaches,eq_converted,eq_twelve_oz,eq_fountain,eq_sellunit
 from dbo.product
where product_desc like 'BIBPST%'
GROUP BY bev_type,franchisor,super_brand,brand,product_code,super_package,package,eq_eaches,eq_converted,eq_twelve_oz,eq_fountain,eq_sellunit
0
 
craigs052998Author Commented:
anee  still gives me 340 rows not the 328 I am looking for
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
can you just paste some duplicate entries here along with the expected results
0
 
craigs052998Author Commented:
CSD      BIBPST CADBURY                 BIBPST DR PEPPER               BIBPST DR PEPPER               4120      BIBPST 5 GAL DR PEPPER                        FOUNTAIN PST/BIB               BIB/PST 5                      13.559716      5      13.3333      5      5

CSD      BIBPST CADBURY                 BIBPST DR PEPPER               BIBPST DR PEPPER               1336      BIBPST 5 GAL DR PEPPER                        FOUNTAIN PST/BIB               BIB/PST 5                      13.559716      5      13.3333      5      5

I only want to see one of them.  The product code is the only non dupe in this one   1336 and 4120


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.