Structured Query Language Frequently Asked Questions

Young woman concentrates on her work in front of computer

alvarez / Vetta / Getty Images

Looking for advice on using the Structured Query Language? This Databases SQL FAQ provides answers to the most frequently asked questions about SQL and databases.

How Can I Retrieve Data From a Database Using SQL?

The SELECT command is the most commonly used command in SQL. It allows database users to retrieve the specific information they desire from an operational database.

How Do I Create a New Database or a New Database Table?

SQL provides the CREATE DATABASE and CREATE TABLE commands to add new databases and tables, respectively to your database. These commands provide a highly flexible syntax allowing you to create tables and databases that meet your specific business requirements.

How Do I Add Data to a Database?

The INSERT command in SQL is used to add records to an existing table.

How Do I Delete Some or All of a Database Table?

Oftentimes, it becomes necessary to remove obsolete information from a relational database. Fortunately, Structured Query Language provides a flexible DELETE command that can be used to remove some or all of the information stored in a table.

What Is a NULL Value?

NULL is the value used to represent an unknown piece of data. Databases treat NULL values in a special way, depending on the type of operation that it is used in. When a ​NULL value appears as an operand to an AND operation, the operation’s value is FALSE if the other operand is FALSE (there is no way the expression could be TRUE with one FALSE operand). On the other hand, the result is NULL (unknown) if the other operand is either TRUE or NULL (because we can’t tell what the result would be.)

How Can I Combine Data From Multiple Database Tables?

SQL join statements allow you to combine data from two or more tables in your query results. Learn how to leverage this powerful technology to supercharge your database queries.

Can I Join a Table to Itself?

Yes, you can use a self-join to simplify nested SQL queries where the inner and outer queries reference the same table. These joins allow you to retrieve related records from the same table.

How Can I Summarize Data Contained Within a Database Table?

SQL provides aggregate functions to assist with the summarization of large volumes of data. The SUM function is used within a SELECT statement and returns the total of a series of values. The AVG function works in a similar manner to provide the mathematical average of a series of values. SQL provides the COUNT function to retrieve the number of records in a table that meets given criteria. The MAX() function returns the largest value in a given data series while the MIN() function returns the smallest value.

How Can I Group Summarized Data?

You may use basic SQL queries to retrieve data from a database but this often doesn’t provide enough intelligence to meet business requirements. SQL also provides you with the ability to group query results based upon row-level attributes in order to apply aggregate functions using the GROUP BY clause.

How Can I Restrict Access to Data Contained Within an SQL Database?

SQL databases provide administrators with a role-based access control system. In this schema, administrators create user accounts for each individual database user and then assign that user to one or more database roles that describe a way the user is allowed to interact with the database. Finally, the administrator grants specific permissions to the role to allow role members to carry out the desired actions. Users are implicitly denied any access that they are not explicitly granted.