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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-10-07 : 07:41:09
|
| Harald writes "HiI am having a brain fart on figuring out the following problem. Let me illustrate what I have and what I want.I have a two tables with the following records:tblDocDocID DocClass===== ========123 Office243 Developer543 DevelopertblAdressDocID ZValue===== =====243 Adr1543 Adr2243 Adr3243 Adr4543 Adr5If I use following statement:select tblAdress.ZValue, tblDoc.DocID, tblDoc.DocClassfrom tblDoc left join tblAdress on tbldoc.DocID = tblAdress.DocIDwhere tblDoc.DocClass = 'Developer'I get following results:ZValue DocID DocClass====== ===== =========Adr1 243 DeveloperAdr3 243 DeveloperAdr4 243 DeveloperAdr2 543 DeveloperAdr5 543 DeveloperWhat I want to do is display only the first record of a DocID. So using the above as an example, the output would be:ZValue DocID DocClass====== ===== =========Adr1 243 DeveloperAdr2 543 DeveloperAny ideas or thoughts? Cheers!Harald" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-10-07 : 07:45:41
|
| By first I assume you mean alphabetically.select DocID, ZValue = min(ZValue)from tblDoc left join tblAdress on tbldoc.DocID = tblAdress.DocID where tblDoc.DocClass = 'Developer' group by DocIDThis will give nulls if no tblAdress entry - if you only want those with an address make it an inner join.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|