Back

Beginner · 12 min

Your first SQL query

Return values with SELECT and name the result columns.

Return a value

SQL describes the result you want from a database. A SELECT statement can return a literal without reading a table. This playground uses SQLite; some syntax differs in PostgreSQL and other database systems.

SELECT 'Hello' AS message;

Output

message
Hello

Name result columns

AS assigns a label to an expression. Single quotes delimit text values. A semicolon ends a statement. The output shows column names followed by rows; each run starts from a fresh sample database.

SELECT 2 + 3 AS total, 'SQL' AS topic;

Output

total | topic
5 | SQL

Put it into practice

  1. Read the sample tables and predict the result before running the query.
  2. Solve the task, compare the returned rows, and explain why the solution works.

Try it yourself

Code runs on this device. When you are signed in, drafts sync to your account.

Run queries on a fresh sample database. Table changes last for this run only; your query draft is saved separately. Results show column names followed by rows. NULL means a missing value.

Apply what you learned

Return the text Hello in a column named message.

Show solution
SELECT 'Hello' AS message;

The SELECT returns one row. The alias gives the output column its requested name.

Practice