Solved

Sql 2008 select with one unique column

Posted on 2011-02-27
4
657 Views
Last Modified: 2012-05-11
How can I select more columns from a table, but one column to be unique ?

I have this query
SELECT Id, Make, Model, Year FROM [VehicleSpecs]

and I want to return fields with unique Make
0
Comment
Question by:evo_x
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:santoshmotwani
ID: 34993680
SELECT distinct Make, ID, Model, Year FROM [VehicleSpecs]
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 34993685
This would do:
SELECT Id, Make, Model, Year
FROM (
SELECT Id, Make, Model, Year, row_number() over ( partition by Make order by ID) rnum
FROM [VehicleSpecs]) temp
WHERE rnum = 1

Open in new window

0
 
LVL 2

Author Comment

by:evo_x
ID: 34993698
Thanks !
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 34993749
Welcome..
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question