Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to do this

Author  Topic 

rkl
Starting Member

3 Posts

Posted - 2004-05-13 : 11:18:30
Hi
I have a query like this:
"SELECT P.id_member,M.namn FROM panel P,member M
WHERE M.id=P.id_member"

that returns:
114 Robin Hood Born To Fun Fun Fun Fun Fun
114 Robin Hood Donkeys in Me
107 Roger Käll Spacecowboys for pleasure buy
107 Roger Käll Amazing
107 Roger Käll Spacecowboys for pleasure buy
111 Don King Cream By Two
111 Don King By the Bell
111 Don King Born To Fun Fun Fun Fun Fun
116 Lisa Morelius Amazing
116 Lisa Morelius Spacecowboys for pleasure buy
116 Lisa Morelius Cream By Two
and so on...

The thing is i only want the first record for each id_member.

How to do this ?

Thanks !
/Roger
Sweden

X002548
Not Just a Number

15586 Posts

Posted - 2004-05-13 : 12:09:01
What do you mean by first?

The order of data in a database has no meaning.

You need to order by something...

And you want Jay's article...

It's listed in this thread..

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=35013



Brett

8-)
Go to Top of Page

rkl
Starting Member

3 Posts

Posted - 2004-05-13 : 12:20:40
Yes, i will order but i didnt include that in this example, just wanted the way to get one record of each id_member.
Go to Top of Page

rkl
Starting Member

3 Posts

Posted - 2004-05-13 : 12:31:35
Thanks to MS Access function FIRST i could do this in ONE Select-statment but it seems not possible in SQL Server. I guess i will have to retrive the id_member column first with a GROUP BY query and then make a querycall for each row returned. I will use this on a asp-webpage.

/Roger
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-05-13 : 13:12:15
[code]

SELECT P.id_member,MIN(M.namn)
FROM panel P,member M
WHERE M.id=P.id_member
GROUP BY P.id_member
[/code]


Brett

8-)
Go to Top of Page
   

- Advertisement -