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 integrated security (SSPI). why we use in the connection string?

2 Answers  


How to use subqueries in the from clause in ms sql server?

0 Answers  


What are security principals used in sql server 2005?

0 Answers  


How to truncate the log in sql server 2012? : sql server database administration

0 Answers  


How will you know when statistics on a table are obsolete?

0 Answers  






What is the server name for sql management studio?

0 Answers  


How much does sql server 2016 cost?

0 Answers  


can you any body tell me while running BCP Out in instance in sql server 2000 is getting error. Error = [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.?

1 Answers  


What is the New in SQL server 2008?

0 Answers  


tell me what are the steps you will take to improve performance of a poor performing query? : Sql server database administration

0 Answers  


What are trace files?

0 Answers  


Difference between primary key and clustered index?

0 Answers  


Categories