This is a discussion on slecting multiple distinct columns.. within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi all... I have a table in which some columns has distinct values and some has duplicates..i wan to ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi all... I have a table in which some columns has distinct values and some has duplicates..i wan to select all the columns with distinct values....no problem if rows has null value in it....i tried a lot wit distinct and group by but nothing got worked out... Waitin for your reply..... Thanking you... |
| |||
| Try the Having clause For example, this will bring back records that have duplicate records for Col1, Col2 and Col3. If you want only records that have a single record, you can change "> 1" to "= 1". SELECT DISTINCT Col1, Col2, Col3, COUNT(*) as NumberDups FROM SomeTable GROUP BY Col1, Col2, Col3 HAVING COUNT(*) > 1 Of course, you could post your table definitions with Create statements and insert statements so people could have data to work with to help you. vvyshak@gmail.com wrote: > Hi all... > I have a table in which some columns has distinct values and some has > duplicates..i wan to select all the columns with distinct values....no > problem if rows has null value in it....i tried a lot wit distinct and > group by but nothing got worked out... > Waitin for your reply..... > Thanking you... |
| ||||
| (vvyshak@gmail.com) writes: > I have a table in which some columns has distinct values and some has > duplicates..i wan to select all the columns with distinct values....no > problem if rows has null value in it....i tried a lot wit distinct and > group by but nothing got worked out... > Waitin for your reply..... I will have to admit that I have a poor understanding of what you are asking for. But there is a standard recommendation for this sort of questions, and that is that you post: o CREATE TABLE statements for your table(s). o INSERT statements with sample data. o The desired output, given the sample data. o A short description of the underlying business problem. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx |
| Thread Tools | |
| Display Modes | |
|
|