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

Do you have any idea about the tcl commands?

0 Answers  


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

0 Answers  


What is difference between commit and rollback when used in transactions?

0 Answers  


How to attach adventureworkslt physical files to the server?

0 Answers  


What are Sql Reporting Services and analysis services? Can u Explain

1 Answers  






What does nvl stand for?

0 Answers  


What are mdf,ndf,ldf files and how to see the data in those files?

6 Answers   Accenture,


How do I view a stored procedure in sql server query?

0 Answers  


What is the diff between Static Queries and Dynamic queries give me some examples

2 Answers   CSC,


What is index, cluster index and nonclustered index?

0 Answers  


Is port 1433 secure?

0 Answers  


What is the template in sql?

0 Answers  


Categories