0

I need one help.I need to fetch some data from one table but one column value should not duplicate.I am explaining my query below.

select  Product_name,pro_Id from db_product_info order by Product_name

Here I need the duplicate value of product name should not fetch.Please help me.

3 Answers 3

1

For this case, You can use group by

SELECT  
    Product_name,
    pro_Id 
FROM 
    db_product_info 
GROUP BY Product_name 
ORDER BY Product_name ASC

See SqlFiddle

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

 select  Product_name,pro_Id from db_product_info group by product_name order by Product_name

Comments

0

The basic way of removing duplicates is to use DISTINCT:

select distinct Product_name,pro_Id 
from db_product_info 
order by Product_name

If you data has Product_name's with different pro_Id's, you need to decide which pro_Id to choose from. In this case you need to use aggregate function (min, max) combibed with GROUP BY:

select Product_name, max(pro_Id)
from db_product_info 
group by Product_name
order by Product_name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.