How to use SELECT DISTINCT as part of a larger query?

I have a table that is poorly designed and I want to replace it with a couple of other tables, but first I have to extract data.

Here are some of the columns of the table:

Location_id, Item_id, Location, Description

The Item_id refers to objects (from another table) that are stored in a location in the location table (location being a room number in a building).

The way it is now, there are multiple repeated values of Location and Description in the table.

I would like to extract Location, Description from that table into a view but I also need to have the view retain one of the Location_id values (it's not important which one, I could use the MINIMUM), but so far I haven't been able to do that.

I can do this:  select distinct location, description but how do I add the minimum location_id into my result set?

Should I be using group by instead of distinct?

Thanks for your help.
gateguardAsked:
Who is Participating?
 
Faiga DiegelConnect With a Mentor Sr Database EngineerCommented:
SELECT DISTINCT location, description, MIN(location_id)
FROM yourtable
GROUP BY location, description
0
 
knightEknightConnect With a Mentor Commented:
select min(Location_id) as Location_id, location, description
from yourTable
group by location, description
0
All Courses

From novice to tech pro — start learning today.