Three elements to an SQL command.

  • keyword
  • identifier
  • optionally one or more literals


  • Select - retrieve data records from a table
  • Insert - add new data record to a table
  • Delete - remove a data record from a table
  • update - Modify data within an existing record in a table.


define the database object in the keyword command.  Can be either a database name, table name, or the names of data fields. Tells use with table to select the data element requested.


Define specific data values referenced by the keyword. String literals must be enclosed in quotes.

Database querys

SQL SELECT statement the searches the database for specific data records.

SELECT datafields FROM table

use commas to separate each data field. When the records that match the query are returned you can determine which data fields to return.  An asterisk will return all fields. Default returns all the data records in the specified table.


WHERE - display a subset of records that meet a specified condition

ORDER BY - display records in a specified order

LIMIT - display only a subset of records

An example of a where statement which allows you to specify conditions to filter data from the results set.

SELECT recipeid, title FROM recipes WHERE recipeid = 1

The order by statement specifies the data field (or fields) you want the returned data to be sorted. This can be ASC or DESC, ascending or descending sort.
an example would be
SELECT commentid, comment FROM comments ORDER BY commentid DESC

The limit statement specifies the starting record and the following number of records to be returned. The starting record is an offset within the returning records and not the actual record id.The offest value starts at 0 and goes to number of records returned in the statement.
An example would be
SELECT recipeid, title FROM recipes ORDER BY recipeid DESC LIMIT 0, 5



Comments (0)

500 characters remaining

Cancel or