Monday 21, May 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    About Us    |    Contact Us

SQL Select

The SELECT statement is used to retrieve data from a table. The general form is as under.

Syntax:

Select fieldname1, fieldname2, fieldname3,…
from tablename;

When retrieving multiple columns, specify each field name. A comma must separate field names. The columns will display in the order you select them.

To select the content of columns named " FirstName" and " LastName" and “Email”, from the database table called " empinfo", use a SELECT statement like this:

empinfo

FirstName
LastName
Email
DOB
Steve
Martin
smart.steve@hotmail.com
08-04-1988
David
Fernandas
davidfernandas@studiesinn.com
04-16-1977
Ajay
Rathor
ajayrathor@studiesinn.com
08-24-1986

SELECT FirstName, LastName FROM  empinfo;

FirstName
LastName
Email
Steve
Martin
smart.steve@hotmail.com
David
Fernandas
davidfernandas@studiesinn.com
Ajay
Rathor
ajayrathor@studiesinn.com

Selecting All Columns:
To get all columns of a table without typing all column names, use:

SELECT * FROM empinfo;

FirstName
LastName
Email
DOB
Steve
Martin
smart.steve@hotmail.com
08-04-1988
David
Fernandas
davidfernandas@studiesinn.com
04-16-1977
Ajay
Rathor
ajayrathor@studiesinn.com
08-24-1986

The Result Set

When a SQL query returns one or more rows of data, you can use the ResultSet object to get the description of the result set and to navigate within the rows of the results to retrieve the data.

SELECT DISTINCT

The DISTINCT command is used with SELECT keyword to retrieve only unique data entries depending on the column list you have specified.  

empinfo

FirstName
LastName
Email
DOB
Steve
Martin
smart.steve@hotmail.com
08-04-1988
David
Fernandas
davidfernandas@studiesinn.com
04-16-1977
Ajay
Rathor
ajayrathor@studiesinn.com
08-24-1986
Steve
Martin
smart.steve@hotmail.com
08-04-1988
David
Fernandas
davidfernandas@studiesinn.com
04-16-1977

SELECT DISTINCT FirstName from empinfo;

The Result will be.

FirstName
LastName
Email
DOB
Steve
Martin
smart.steve@studiesinn.com
08-04-1988
David
Fernandas
davidfernandas@studiesinn.com
04-16-1977
Ajay
Rathor
ajayrathor@studiesinn.com
08-24-1986

 


 
     
   
SQL Tutorial
 
  SQL Introduction
SQL Introduction
  SQL Select
SQL Select
  SQL Where Clause
SQL Where Clause
  SQL Distinct
SQL Distinct
  SQL AND Operator
SQL AND Operator
  SQL OR Operator
SQL OR Operator
  SQL Order By
SQL Order By
  SQL Insert
SQL Insert
  SQL Update
SQL Update
  SQL Delete
SQL Delete
  SQL Join
SQL Join
  SQL Inner Join
SQL Inner Join
  SQL Left Join
SQL Left Join
  SQL Right Join
SQL Right Join
  SQL Full Join
SQL Full Join
  SQL Create Database
SQL Create Database
  SQL Create Table
SQL Create Table
  SQL Constraints
SQL Constraints
  SQL Alter Table
SQL Alter Table
  SQL Truncate Table
SQL Truncate Table
  SQL Drop
SQL Drop
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Evaluating Java for Game Development  Ebook Evaluating Java for Game Development
   
Download Computational Modeling and Complexity Science  Ebook Computational Modeling and Complexity Science
   
Download PDQCash Ebook PDQCash
   
Download Java Learning Made Easy  Ebook Java Learning Made Easy
   
Download PHP 5 Power Programming  Ebook PHP 5 Power Programming
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz