Help Center/
GaussDB/
Developer Guide(Centralized_8.x)/
SQL Reference/
SQL Syntax/
S/
SELECT/
Simple Queries
Updated on 2024-06-03 GMT+08:00
Simple Queries
A simple query retrieves one or more columns of data from one or more tables or views.
-- Create a table and insert data into the table. gaussdb=# CREATE TABLE student( sid INT PRIMARY KEY, class INT, name VARCHAR(50), sex INT CHECK(sex = 0 OR sex = 1) -- Gender. 1: male; 0: female ); gaussdb=# INSERT INTO student (sid, class, name, sex) VALUES (1, 1, 'Michael', 0); gaussdb=# INSERT INTO student (sid, class, name, sex) VALUES (2, 2, 'Bob', 1); gaussdb=# INSERT INTO student (sid, class, name, sex) VALUES (3, 2, 'Gary', 0); -- Query some columns. gaussdb=# SELECT sid, name FROM student; sid | name -----+--------- 1 | michael 2 | bob 3 | Gary (3 rows) -- Query all columns. gaussdb=# SELECT * FROM student; sid | class | name | sex -----+-------+---------+----- 1 | 1 | michael | 0 2 | 2 | bob | 1 3 | 2 | Gary | 0 (3 rows) -- Specify the column alias. gaussdb=# SELECT sid student_id, name FROM student; student_id | name ------------+--------- 1 | michael 2 | bob 3 | Gary (3 rows) -- Delete. gaussdb=# DROP TABLE student;
Parent topic: SELECT
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot