Format of SQL queries

A simple SQL query includes just a few statements.

When you enter SQL statements on the SQL Query panel, you need to know the following items:

  • The name of the table from which you want data
  • The column names in the table
  • The row conditions you want to specify
  • The sequence in which you want the data to appear

Many simple SQL queries use the following basic SQL statement:

SELECT columnname
 FROM tablename
 WHERE condition
 ORDER BY columnname

The following figure shows a basic SQL query. This query displays the employee names, years of service, and salaries from the Q.STAFF table.

Figure 1. A basic SQL query
 SQL QUERY                               MODIFIED    LINE 1
 
 SELECT NAME, YEARS, SALARY
   FROM Q.STAFF
   ORDER BY NAME
 
 
 
 
 
 
 
 
 
 
 *** END ***
 
 
 1=Help       2=Run        3=End      4=Print     5=Chart        6=Draw
 7=Backward   8=Forward    9=Form     10=Insert   11=Delete       12=Report
 OK, cursor positioned.
 COMMAND ===>                                   SCROLL ===> PAGE