Solved

query in sql server

Posted on 2007-04-10
3
241 Views
Last Modified: 2010-03-19
In sql server I have the following table:
ID                 Name
aaa             desc of aaa
bbb             desc1 of bbb
bbb            desc2 of bbb
ccc            desc of ccc
I want to create a new table or a query that for each ID will show the first Name that exist.
How do I do it?
Thankyou
Anat
0
Comment
Question by:ANAT2403
3 Comments
 
LVL 8

Expert Comment

by:MOA81
ID: 18881089
Dear ANAT2403

what do you mean by first name

as for the query

select ID,Name from Table

??

but what do u mean by first name

can you make an example of the above table
0
 
LVL 17

Accepted Solution

by:
HuyBD earned 500 total points
ID: 18881117
select ID,(select top 1 from table as t where t.ID=table.ID) as name
from table
group by ID

replace table with your table name

HuyBD;
0
 

Author Comment

by:ANAT2403
ID: 18881170
hi HuyBD,
very good execp one correction instead of  top 1
it shoul be top 1 name
thankyou
anat
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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