Help Center/
GaussDB/
M-Compatibility Developer Guide(Centralized)/
SQL Reference/
SQL Syntax/
SQL Statements/
S/
SELECT/
Simple Queries
Updated on 2025-10-23 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.
m_db=# CREATE TABLE student(
sid INT PRIMARY KEY,
class INT,
name VARCHAR(50),
gender INT CHECK(gender = 0 OR gender = 1) -- Gender (1: male; 0: female).
);
m_db=# INSERT INTO student (sid, class, name, gender) VALUES (1, 1, 'Michael', 0);
m_db=# INSERT INTO student (sid, class, name, gender) VALUES (2, 2, 'Bob', 1);
m_db=# INSERT INTO student (sid, class, name, gender) VALUES (3, 2, 'Gary', 0);
-- Query some columns.
m_db=# SELECT sid,name FROM student;
sid | name
-----+---------
1 | michael
2 | bob
3 | Gary
(3 rows)
-- Query all columns.
m_db=# SELECT * FROM student;
sid | class | name | gender
-----+-------+---------+-----
1 | 1 | michael | 0
2 | 2 | bob | 1
3 | 2 | Gary | 0
(3 rows)
-- Assign an alias to a column.
m_db=# SELECT sid student_id, name FROM student;
student_id | name
------------+---------
1 | michael
2 | bob
3 | Gary
(3 rows)
-- Drop.
m_db=# 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