SQL SELECT DISTINCT Statement

(0 votes, average 0 out of 5)

To select information from a database without listing duplicates in the same column, use the SELECT DISTINCT statement in SQL. 

Syntax:

 

1
SELECT DISTINCT <column name(s)> FROM <table name>

 

For the column name(s) field, enter the names of the columns you would like to pull the distinct data from in the table.

For the table name, enter the name of the table from which you are accessing the data.

 

Examples:

Suppose we have the following dataset in our database within a table named birthdays:

FirstName LastName BirthDate
Brian Johnson 1/8/1975
Nick Thomson 3/19/1965
Tyler Jones 1/17/1994

Ben Thomson 2/8/1987

To select distinct last ones, use the following query:

1
SELECT DISTINCT LastName FROM birthdays

Which would yield the following result set:

LastName
Johnson
Thomson
Jones


Partner Links:
Last Updated on Friday, 02 July 2010 08:05  
Related Articles

» How to install Adobe Photoshop CS5 In Ubuntu Linux using WINE

These instructions were tested with Adobe Photoshop CS5.1 (the 30-day trial from Adobe's website) under Ubuntu 11.10 using WINE 1.4-rc5. I was not able to get the installer to work, however the method of installing on Windows and then copying over did work (see ). The directories I copied were:C:\Program Files\Adobe\ C:\Program Files\Common Files\Adobe C:\Program Files (x86)\Adobe C:\Program Files (x86)\Common Files\Adobe C:\Users\All Users\Application Data\Adobe\CS5Note: you must copy each...

» How to change the primary monitor in Ubuntu or other Linux distributions

Using dual or multiple monitors in Linux is relatively straightforward as most monitors are automatically detected on the major distributions. However, Gnome does not give an option for specifying which monitor is the primary - that is to say the monitor which holds the panels by default and is considered the 'default' display. Fortunately, the xrandr utility can easily switch which monitor is the primary. Copy and paste the following script into a text file called monitor-switcher.sh. Monitor...

» ASP.NET Error: Cannot create/shadow copy when that file already exists.

 Occasionally when using a debugger in ASP.NET (or shortly after using the debugger), your solution may return the following error when viewing in a browser:Cannot create/shadow copy when that file already exists.This is a problem rooted in how solutions build for ASP.NET - they are often built into binaries that are placed in a "shadow" location so that the user may continue editing and saving the code without any consequence to the current built solution.  Sometimes this process will...