Free Newsletters:
DatabaseDaily  
Database Journal
Search Database Journal:
 
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum DBA Videos
internet.com

» Database Journal Home
» DBA Videos
» Database Articles
» Database Tutorials
MS SQL
Oracle
MS Access
MySQL
DB2
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» DBA Jobs
» Sitemap

News Via RSS Feed



follow us on Twitter

Marketplace Partners
Be a Marketplace Partner

internet.commerce
Be a Commerce Partner


















Mariposa Bot Shipped With Vodafone Smartphone

IT Job Market Heating Up: Report

Bing Makes Strides But Momentum Stalls

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Database Journal | DBA Support | SQLCourse | SQLCourse2







Systems Engineer Sr - Solaris - Linux (TX)
Next Step Systems
US-TX-Houston

Justtechjobs.com Post A Job | Post A Resume

Featured Database Articles

SQL Etc

August 18, 2000

Simple SQL: Pt. 1

By Ted Brockwood

Getting Acquainted with DISTINCT

An excellent keyword to get acquainted with is "DISTINCT". If you have data that is duplicated, but you only want to see one instance of it, DISTINCT is just the ticket.

For example, you have a table named CUSTOMERS. It is loaded with the names, addresses, phone numbers, and company names of all your best customers. Your boss needs to know what companies have been buying from you. Frequently you have multiple buyers from the same company, perhaps different divisions, so running a standard SELECT statement like this:

SELECT FIRST_NAME, LAST_NAME, COMPANY
       FROM CUSTOMERS;

will return something like this:

FIRST_NAMELAST_NAMECOMPANY
JoeJonesIsoLunacy, Inc
DonnaSprintMegaData Systems Corp
WillBrownIsoLunacy, Inc

As is obvious, you have two customers from IsoLunacy, Inc in your query results. If this were thousands of duplicates, it would be a terrible headache to create a list manually of companies you deal with. So, you fire off a DISTINCT query such as this:

SELECT DISTINCT COMPANY FROM CUSTOMERS;

Which returns:

COMPANY
IsoLunacy, Inc.
MegaData Systems Corp

SELECT statements are also adept at handling comparisons such as greater than and less than. Imagine the table "EMPLOYEES" with Names, Addresses, Start dates, vacation days accrued, and vacation days taken contained within it. The boss wants to know (for the Human Resources Intranet) whether anyone has taken more vacation days than they have accrued. Your SELECT might look like this:

SELECT FIRST_NAME,LAST_NAME FROM EMPLOYEES
       WHERE VACATION_TAKEN > VACATION_ACCRUED;

The results might look like:

FIRST_NAMELAST_NAME
JoeSmith

Good information for HR, and bad information for the employee names resulting from this query.

Go to page: Prev  1  2  3  4  Next  

Tools:
Add databasejournal.com to your favorites
Add databasejournal.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

SQL etc Archives








Latest Forum Threads
SQL etc Forum
Topic By Replies Updated
help with joining table and view stong 2 March 17th, 11:27 PM
return null when where has no result bugmenot1 0 March 15th, 06:17 AM
What does * mean tonyd 1 March 11th, 09:07 AM
Searching by time and grouping by numer padstar 4 February 22nd, 02:01 PM









The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers