Solved

Sql 2008 select with one unique column

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Table where row act as column 11 68
Conditions in Where clause 9 46
SQL Select - identify record discrepancies 1 30
online  environment for testing sql queries 5 29
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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

740 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