Basic SQL Query Syntax

Instructor: Kent Beckert

Kent is an adjunct faculty member for the College of Business at Embry-Riddle Aeronautical University and has a Master's degree in Technical Management.

In this lesson, we will describe SQL queries and how these queries are used to access data stored in a relational database. We will also discuss SQL statements and the SQL clauses used to construct these statements.

Query Concepts

Here it is, just three weeks on the job and the boss has asked you to retrieve several important records from the company's relational database. No problem, the boss has given you the critical search criteria: Topic, Teacher, and School. The next morning, you arrive at your terminal, access the relational database, and, using a query, you enter the search criteria given to you. You hit the execute key, but no records are retrieved. You try it a second time; still nothing works. Later in the day, you find out you had the right search criteria, but you did not fully understand database concepts or the proper syntax required to form a query. With this in mind, let's review three important concepts: syntax, relational database, and structural query language (SQL).

What is Syntax?

The term syntax refers to strict structural patterns used when creating a query. As soon as you enter the search criteria using the correct syntax, the query should execute, and the requested records retrieved from the target database. Remember that database query languages may be database-dependent and may not execute across different database platforms. It is always a good idea to check for compatibility before beginning your programming work.

What is a Relational Database?

A relational database, unlike other types of databases maintains a set of separate files (tables), having related data elements in multiple tables. Data stored in a relational database are composed of files, files composed of records, and records composed of fields. Examples of commonly used relational databases include: Oracle, DB2, SQL Server, and MySQL, to name a few.

What is Structural Query Language (SQL)?

SQL is a programming language designed to retrieve data stored in a database. SQL works in conjunction with a database management system (DBMS), enabling data control and retrieval to and from a relational database. Programming in SQL requires strict adherence to syntactical rules and guidelines. Understanding these guidelines will enhance the programmer's ability to create and execute effective queries leading to the successful retrieval of needed information.

SQL Clauses

Clauses are used to construct an SQL statement so that when executed the statement will perform a particular function. It is important to note that not all clauses are required for use with an SQL SELECT statement. The table below lists and describes the most commonly used SQL clauses. An asterisk '*' adjacent to an SQL clause indicates the clause is optional.

SQL Clause Function Performed
SELECT Specifies the fields containing the target data
FROM Identifies the specific table or tables containing the fields specified in the SELECT clause
*WHERE Identifies the criteria to be matched for inclusion in the results
*ORDER BY Establishes the sorting requirements for retrieved data

SQL Statements

An SQL statement is composed of at least two, but typically three, of the basic SQL clauses discussed earlier. These statements are used together to access a set of data stored in a database. To construct an SQL statement, the programmer must have detailed knowledge about the data being retrieved from a database. To be successful the programmer must know:

  • Where the desired data are stored (i.e. Table name)
  • Specifically what data is desired
  • What search criteria will return the desired results
  • Where to store the results

For example, a simple SQL statement used to obtain a list of movies from the database named Movies, and the title contains the word Rocky could be constructed as:

SELECT Movie_Title
FROM Movies
WHERE Title = 'Rocky';

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support