Sql Distinct more than 1 coloum

hey i have a problem in my sql statment:

select catalog_id, min(id), min(prod_id), min(prod_title), min(prod_price), min(prod_description), min(prod_image)
  from Products
group by catalog_id

i need to select more than one coloum  but i can't pull the image coloum, can any one help me?
JCWEBHOSTAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
Can you please elaborate on what you are after with some sample data rows?
What does that query not give you? (it has correct syntax)
JCWEBHOSTAuthor Commented:
i want an sql statement to display distinct rows :

here is my sql statment:


select DISTINCT  catalog_id, id from Products

outputs:  
catalog_id  id          
----------- -----------
20          25          
20          26          
20          27          
20          28          
20          29          
20          30          
20          31          
20          32          
20          33          
20          36          
20          39          
24          37          
24          38    


i want it to output  only 2 rows

catalog_id  id          
----------- -----------
20          25          
24          37

and i need to out more than 1 coloum e.g images, int varchar
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you have not read my follow.comment here:http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_26550512.html
select *
  from ( select t.*, row_number() over (partition by catalog_id order by id ) rn
          from yourtable t
  ) sq
where sq.rn = 1

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

JCWEBHOSTAuthor Commented:
can you break that code down and make it easy to under stand? please
JCWEBHOSTAuthor Commented:
ok thanks now i understand
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you could read this article to understand:
http://www.experts-exchange.com/A_3203.html
cyberkiwiCommented:
Are these easier to understand?
Works on MySQL as well.

select * from Products
where ID in
(
select min(id)
from Products
group by catalog_id
)

or

select p.*
from
(
select min(id) as MinID
from Products
group by catalog_id
) m inner join Products p on MinID=p.id
BrandonGalderisiCommented:
For performance sakes, you may want to consider using an exists() based correlated sub-select to get your min IDs.  I've done some performance testing and it is going to be faster.

http://sqlservernation.com/blogs/brandongalderisi/archive/2009/09/20/using-row-number-vs-a-correlated-sub-select.aspx
JCWEBHOSTAuthor Commented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.