SELECT
The SELECT statement retrieves data from one or more tables. Use SELECT to:
-
Retrieve specific columns from a table.
-
Query data across multiple tables.
-
Filter results based on specific criteria.
Syntax
To retrieve data from a table, use this syntax:
SELECT * FROM default_redpanda_catalog=>table_name;
To filter by specific columns, use:
SELECT column1, column2, ...
FROM default_redpanda_catalog=>table_name;
Where:
-
SELECT: Specifies the data to retrieve. -
*: Returns all columns. -
FROM: Specifies the table to query. -
table_name: The name of the table. -
column1, column2, …: The columns to retrieve.
|
The |
Examples
The following examples query a table named student_data that contains student records with id, name, and domicile columns.
Query data from all columns
-
To display all the data from the
student_datatable, use this syntax:SELECT * FROM default_redpanda_catalog=>table_name; -
Run the following query:
SELECT * FROM default_redpanda_catalog=>student_data; -
The query returns:
+--------+----------+----------------+ | id | name | domicile | +--------+----------+----------------+ | 119291 | Jordan | Los Angeles | | 119292 | Mike | Melbourne | | 119293 | Will | Sydney | +--------+----------+----------------+
Query data from specific columns
-
To get the list of students' names with their IDs, use this syntax:
SELECT column_1, column_2 FROM default_redpanda_catalog=>table_name; -
Run:
SELECT id, name FROM default_redpanda_catalog=>student_data; -
The query returns:
+--------+----------+ | id | name | +--------+----------+ | 119291 | Jordan | | 119292 | Mike | | 119293 | Will | +--------+----------+
Query data from a specific column with the condition
-
With a large amount of data, skimming for the desired data can take a long time. Apply conditions to the
SELECTstatement to narrow the results:SELECT column_1 FROM default_redpanda_catalog=>table_name WHERE condition; -
To find the student who lives in Sydney, run:
SELECT name FROM default_redpanda_catalog=>student_data WHERE domicile='Sydney'; -
The query returns:
+----------+ | name | +----------+ | Will | +----------+
SELECT DISTINCT
To return only unique rows from the result set, add the DISTINCT keyword after SELECT:
SELECT DISTINCT column1, column2, ...
FROM default_redpanda_catalog=>table_name;
DISTINCT deduplicates rows based on the combined values of all listed columns.
|
Redpanda SQL does not support |