SELECT Statements

A tutorial example is provided on how to use SELECT statements to retrieve from database as multiple rows and multiple fields in each row.

A select statement is also called a query statement. It is normally used to retrieve rows of data selected from specified tables. The generic syntax of a select statement is:

SELECT select_expression_list [FROM clause]

where "expression_list" defines a list of select expressions, and "FROM clause" defines a select table with rows and columns of values. Column names of the select table can be used as variables in select expressions to represent column values in each row.

When a select statement is executed, a nested loop logic will be performed to generate rows of output data:

Loop on each row of the select table, do:
   Loop on each select expression, do:
      Evaluate this expression with possible column values in current 
         row of the select table.
   End of loop
   Return the results of all select expressions as a row of output data
End of loop

Note:

Sample select statements without FROM clause:

SELECT 'Hello world!';
SELECT 'Apple', 'Orange';
SELECT CHAR_LENGTH('Hello world!');
SELECT 1, 4, 9, 16, 25;
SELECT PI();
SELECT CURRENT_DATE(), CURRENT_TIME();

Last update: 2015.

Table of Contents

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 Perl Programs and MySQL Servers

 PHP Programs and MySQL Servers

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

 Character Strings and Bit Strings

 Commonly Used Functions

 Table Column Types for Different Types of Values

 Using DDL to Create Tables and Indexes

 Using DML to Insert, Update and Delete Records

Using SELECT to Query Database

SELECT Statements

 FROM Clause of a SELECT Statement

 JOIN -Operations to Join Two Tables

 JoinTable.sql - Example of Join Tables

 WHERE Clause of a SELECT Statement

 GROUP BY Clause of a SELECT Statement

 ORDER BY Clause of a SELECT Statement

 Transaction Management and Isolation Levels

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 Outdated Tutorials

 References

 PDF Printing Version