how can u select the Distinct values in the table, table
having 20 columns , i want all columns

Answers were Sorted based on User's Feedback



how can u select the Distinct values in the table, table having 20 columns , i want all columns..

Answer / uma

The SELECT DISTINCT Statement
The DISTINCT keyword is used to return only distinct
(different) values.
The SELECT statement returns information from table columns.
But what if we only want to select distinct elements?
With SQL, all we need to do is to add a DISTINCT keyword to
the SELECT statement:

Syntax
SELECT DISTINCT column_name(s)
FROM table_name

Using the DISTINCT keyword To select ALL values from the
column named "Company" we use a SELECT statement like this:
SELECT Company FROM Orders
"Orders" table

Company OrderNumber
Sega 3412
W3Schools 2312
Trio 4678
W3Schools 6798
Result

Company
Sega
W3Schools
Trio
W3Schools
Note that "W3Schools" is listed twice in the result-set.
To select only DIFFERENT values from the column named
"Company" we use a SELECT DISTINCT statement like this:
SELECT DISTINCT Company FROM Orders

Result:
Company
Sega
W3Schools
Trio
Now "W3Schools" is listed only once in the result-set.

Is This Answer Correct ?    6 Yes 3 No

how can u select the Distinct values in the table, table having 20 columns , i want all columns..

Answer / krishnamoorthy.n

select distinct * from <tablename>

Is This Answer Correct ?    4 Yes 3 No

Post New Answer

More SQL Server Interview Questions

What is partition index in sql server?

1 Answers  


How to bind a view to the schema of the underlying tables?

1 Answers  


Tell me what is the difference between locking and multi-versioning?

1 Answers  


how to find number of columns in a table in sql server 2000 and 2005 also

7 Answers   HCL, Virtusa,


What is create statement?

1 Answers  


How to loop through the result set with @@fetch_status?

1 Answers  


What is sql server replication? : sql server replication

1 Answers  


I am using SQL Server 2005, I have some select and update statements in my query with WHERE clause I want to prevent these queries from SQL injection attacks. What are the steps and precautions to be taken for SQL Injection attacks? Does anybody have suggestions? Thanks in advance,

2 Answers  


How to create new tables with "select ... Into" statements in ms sql server?

1 Answers  


What are transactions and its controls?

1 Answers  


Does index speed up select statements?

1 Answers  


What is data mart? : sql server analysis services, ssas

1 Answers  


Categories