Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sql 2008 select with one unique column

Posted on 2011-02-27
4
Medium Priority
?
673 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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

772 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