Solved

Sql 2008 select with one unique column

Posted on 2011-02-27
4
610 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
  • 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now