Basic Query Syntax

This document introduces basic queries in SynxDB.

SynxDB is a high-performance, highly parallel data warehouse developed based on PostgreSQL and Greenplum. The following are some examples of basic query syntax.

  • SELECT: Used to retrieve data from databases and tables.

    SELECT * FROM employees;  -- Query all data from the employees table.
    
  • Conditional queries (WHERE): Filter result sets based on specific conditions.

    SELECT * FROM employees WHERE salary > 50000;  -- Query employee information with salaries exceeding 50,000.
    
  • ORDER BY: Used to sort query results by one or more columns.

    SELECT * FROM employees ORDER BY salary DESC;  -- Sort employee information by salary in descending order.
    
  • Aggregate functions: Used to calculate statistical information from data sets, such as COUNT, SUM, AVG, MAX, MIN.

    SELECT AVG(salary) FROM employees;  -- Calculate the average salary of employees.
    
  • GROUP BY: Used with aggregate functions to specify column information for group aggregation.

    SELECT department, COUNT(*) FROM employees GROUP BY department;  -- Count the number of employees by department.
    
  • Limiting result quantity (LIMIT): Used to limit the number of rows returned by query results.

    SELECT * FROM employees LIMIT 10;  -- Query only the first 10 employees' information.
    
  • Join queries (JOIN): Used to combine data from two or more tables based on related columns.

    SELECT employees.name, departments.name
    FROM employees
    JOIN departments ON employees.department_id = departments.id;  -- Query employees and their corresponding department names.
    
  • Subqueries: Nested queries within another SQL query.

    SELECT name FROM employees
    WHERE department_id IN (SELECT id FROM departments WHERE location = 'New York');  -- Query all employees working in New York.
    

The above is just a brief overview of basic query syntax in SynxDB. SynxDB also provides more advanced queries and features to help developers perform complex data operations and analysis.