SQL SELECT Statement

(0 votes, average 0 out of 5)

A select statement in SQL is used to collect data from a database. The data that is pulled from the database is stored in a table-like structure, called a result-set.

Syntax:

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

In the column name(s) field, you can enter single or multiple column names to select a set of columns or an asterisk (*) to select all columns from the table.

In the table name field, you must enter a single valid table name.

Note: SQL is not case sensitive. 'SELECT' is the same as 'select'.

 

Example:

Suppose we had a database with the following information:

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

Table Name: birthdays

 

To select ALL of the information from the table, one would use the following query:


1
SELECT * FROM birthdays

Which would yield the following results:

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

 

To select First and Last names from the database, one would use the following query:

1
SELECT FirstName, LastName FROM birthdays

Which would yield the following results:

FirstName LastName
Brian Johnson
Nick Thomson
Tyler Jones

 

To select only First names from the database, one would use the following query:

1
SELECT FirstName FROM birthdays

Which would yield the following results: 

FirstName
Brian
Nick
Tyler
Partner Links:
Last Updated on Thursday, 01 July 2010 22:06  
Related Articles

» For Loops in PHP

To create a for loop in php, follow these simple steps:Set a counter variable to some initial value.Check to see if the conditional statement is true.Execute the code within the loop.Increment a counter at the end of each iteration through the loop.The following is pseudo php code for a for loop:123for(init counter; conditional statement; increment counter){ inner code;}As you can see, all of the above steps are taken care of within the for loop, making the syntax short and easy to...

» 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...

» How to Change Mouse Sensitivity in Windows 7

To change how sensitive your mouse is in Windows 7, navigate to the Start button in the left hand corner and click "Control Panel".  In the search box, search for "mouse".Click on the "Change mouse settings" option and navigate to the "pointer options" tab on the top.The "Select a pointer speed" bar controls how sensitive your mouse is.  Adjust it accordingly and press Apply to save the changes.