Search

Wednesday, December 18, 2013
0 comments

How to Retrieve Records without Duplication of Values: SQL Programming

8:12 AMWednesday, December 18, 2013
Redundancy is each second programmer’s problem in querying with sql programming. Sql programming provides some in-built keyword that may be used to remove this problem. The article shows syntax and use of this keyword with examples.

When there is a requirement to eliminate rows with duplicate values in a column, the DISTINCT keyword is used. The DISTINCT keyword eliminates the duplicate rows from the result set.

The syntax of the DISTINCT keyword is:

SELECT [ALL|DISTINCT] column_names
FROM table_name
WHERE search_condition

Where

  • column_names: name of fields to be displayed in output.
  • table_name: name of table from which records are to be retrieved.
  • Search_condition: mostly used to filter the output.
  • DISTINCT keyword specifies that only the records containing non-duplicated values in the specified column are displayed.

In a query that contains the DISTINCT keyword, you can specify more than one column name. In that case, the DISTINCT keyword is applied to all the columns that are there in the select list. You can specify DISTINCT only before the select list. The following SQL query retrieves all the Titles beginning with PR from the Employee table:

SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle LIKE 'PR%'

Output: The result contains all the records of employee table having PR, the starting two characters. The query will display only the JobTitle field, as specified in the query.

How to Retrieve Records without Duplication of Values: SQL Programming


Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top