Select a single column #
What are SQL statements #
SQL statements are commands used to perform operations on a relational database. These statements are essential for interacting with the database, whether it's for querying data, updating records, or managing the structure of the database.
SELECT command #
The SELECT command in SQL is used to retrieve data from one or more tables in a relational database. It allows users to specify the columns they want to retrieve, the table or tables from which to retrieve the data, and conditions to filter the results. The SELECT statement is a fundamental component of SQL queries and is extensively used for data retrieval and analysis.
The basic syntax of the SELECT statement is as follows:
SELECT column_name FROM table;
column_name: Specify the column you want to retrieve.table: Specifies the table from which to retrieve the data.
Semicolon is the standard way to separate each SQL statement in database systems that allows more than one SQL statement to be executed in a single call.
Some database systems require a semicolon ; at the end of each SQL statement.
In this course, we will use semicolon at the end of each SQL statement for clarity.
Exercise #
We have already created a table customers with the columns first_name, last_name, age, and gender. Write a command to retrieve first_name column from customers table.
Tests #
- The result has
first_namecolumn.
Solution
SELECT first_name FROM customers;
Basic Data Retrieval