how can u select the Distinct values in the table, table
having 20 columns , i want all columns
Answer Posted / 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 |
Post New Answer View All Answers
What are a scheduled jobs?
What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting is possible?
explain declarative management framework (dmf) in sql server 2008?
How can you stop stored procedures from recompiling?
How can I check if a view exists in a sql server database?
What are rows and columns?
How to get a list of table columns using the "sp_columns" stored procedure in ms sql server?
What is #temp and @table variable in SQL server?
How to use old values to define new values in update statements in ms sql server?
How do I find the size of a sql server database?
What are the common performance issues in sql server?
What do you mean by authentication modes in sql server?
How do you debug a procedure in sql server?
What is the difference between resultset and resultsetmetadata?
Explain what is scheduled job and how to create it?