You are here: Re: Select distinct one some fields, but return all feilds « MsSQL Server « IT news, forums, messages
Re: Select distinct one some fields, but return all feilds

Posted by David Portas on 06/08/05 23:27

What's the key of this table? It would be useful to know. Assuming it is
key_col, you could do this:

SELECT code1, code2, code3, foo1, foo2
FROM YourTable AS T
WHERE key_col =
(SELECT MIN(key_col)
FROM YourTable
WHERE code1 = T.code1
AND code2 = T.code2
AND code3 = T.code3)

This also assumes that code1, code2 and code3 are non-nullable columns.
Again, it does help if you post a better spec of your problem. The best way
is to include DDL (CREATE TABLE statement including keys and constraints),
sample data (INSERT statements) and show your required end results.
Otherwise answers are just guesswork.

--
David Portas
SQL Server MVP
--

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация