iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning SQL Course: Select Data - www.itechcollege.com SQL Course: Select Data - www.itechcollege.com
Online Degrees Scholarships & Fellowships Internships Student Financial Aid Study Abroad Itech Bookstore
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
ASP.NET
SQL
AJAX
FTP
XML
Career Center
Job List
Web Jobs
Student Jobs
Computer Jobs
Engineer Jobs
Developer Jobs
Job Search
Resume Writing
Job Interview
Salary Info


itech > courses > SQL > Select Data

Select Data

select statement is used to query data from a database. A select statement might be as follows:

   select user, pass, page from members
     where user = 'John';

"user", "pass" and "page" are column names. You can select as many column names as you want, or you can use a "*" to select all columns:

   select * from members
     where user = 'John';

"members" is table name that follows the keyword from.

The where clause (optional) specifies which data values or rows will be returned or displayed, based on the criteria described after the keyword where. Note: if the value is a string, then it should be enclosed in single quotes, and numbers should not.

You can use any of the following logical operators in your where clause to restrict the rows you retrieve.

Logical Operators
= Equal to
!= or <> Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
in Equal to any item in a list
not in  Not equal to any item in a list
between Between two values, greater than or equal to one and less than or equal to the other
not between Not between two values
begins with Begins with specified value
contains Contains specified value
not contains Does not contain specified value
is null Is blank
is not null Is not blank
like Like a specified pattern. % means any series of characters. _ means any single character.
not like Not like a specified pattern. % means any series of characters. _ means many single character.


like allows you to select all data that is similar to what you specify. In SQL, the percent symbol "%" acts as a wildcard to represent any string of characters, including an empty string, and the underscore character "_" acts as a wildcard to represent any single character. For example:

  select user, pass, page from members
    where user LIKE 'Jo%';

This statement will match any user names that start with 'Jo'.

Or you can specify,

  select user, pass, page from members 
    where user LIKE '%e';

This statement will match any last names that end in a 'e'.

Examples of some other operators:

  select price from product where price > 10;


  select * from product where price between 10 and 100;

You can use key words order by for sorting your data. For example, you can order your data by user name.

 select * from members
    order by user 

By default, order by clause orders the specified fields in ascending order.

If you want the data in the specified field displayed in descending order (Z to A, 100 to 1), you can add "desc" after a column name:

  select * from members 
    order by user desc 

You can add multiple criteria to your where clauses by using "and" or "or.":

  select user, pass, page from members 
    where user = 'John' and pass='John123';
  Back to Index Page
Next Page >>   Introduction
Select Data
Insert Update and Delete Data
Create Alter and Drop Table
 

SQL Books
SQL Jobs



Bookmark:  del.icio.us digg facebook Reddit Mixx BlinkList Fark Furl NewsVine Simpy Spurl Segnalo Technorati blogmarks Google YahooMyWeb Windows Live



SQL Course: Select Data - www.itechcollege.com
Copyright ©2008, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech