DQL operations for logical tables
This topic describes the Data Query Language (DQL) statements for logical tables.
Limits
A SELECT statement can return a maximum of 10,000 rows, and the result set must be smaller than 10 MB. This limit does not apply if the SELECT statement is a subclause. A SELECT subclause returns all results to the parent query.
By default, full table scans are disabled for SELECT statements that query partitioned tables.
Standard SELECT query
Dataphin supports standard SELECT statements to query logical tables. You can use these statements to retrieve data from a table that meets specified conditions.
[with <cte>[, ...] ]
select [all | distinct] <select_expr>[, <except_expr>)][, <replace_expr>] ...
from <ld_data_unit>.<logical_table_name>
[where <where_condition>]
[group by {<col_list>|rollup(<col_list>)}]
[having <having_condition>]
[order by <order_condition>]
[distribute by <distribute_condition> [sort by <sort_condition>]|[ cluster by <cluster_condition>] ]
[limit <number>]
[window <window_clause>]The data block name cannot be omitted.
Example
For example, after you create a logical table named `user` in Dataphin, you can use the following command to query data from it.
SELECT * FROM ld_test.dim_user WHERE ds>0;Special SELECT queries (WHERE clause)
In addition to standard SELECT statements, Dataphin provides a special syntax for querying fields from associated logical tables. This syntax can significantly simplify your SQL code and improve efficiency.
select <table_alias>.<column_list>
,<table_alias>.<dim_role>[.<dim_role>].<dim_columnn_list>
from <ld_data_unit>.<logical_table_name> <table_alias>
where <where_condition>Command description:
table_alias: The alias of the logical table to query. This alias is required.
dim_role: The role name of the associated logical dimension table in the primary table.
column_list: The fields of the primary table.
dim_column_list: The fields of the associated logical dimension table.
ld_data_unit: The name of the data block.
Example:
In this example, a logical fact table for orders named ld_test.fct_crt_sale_order_id is associated with a customer logical dimension table (ld_test.dim_customer) and an address logical dimension table (ld_test.dim_address). The address table is also associated with a city logical dimension table (ld_test.dim_region_lvl3). The city table is a hierarchy dimension table and has the role name `dim_city` in the `dim_address` table.

For example, to query the customer name and delivery city for a specific order where the order ID is 123, use the following statement:
select crt_sale_order_id
,ord.dim_customer.user_name
,ord.dim_address.dim_city.region_lvl3_name as city_name
from ld_test.fct_crt_sale_order_di ord
where ds = '20230101'
and crt_sale_order_id = 123The preceding statement is equivalent to the following standard SQL statement:
select crt_sale_order_id
,cust.user_name
,city.region_lvl3_name as city_name
from (select *
from ld_test.fct_crt_sale_order_di
where ds = '20230101'
and crt_sale_order_id = 123) ord
left outer join
(select *
from ld_test.dim_customer
where ds = '20230101') cust
on (ord.customer_id = cust.customer_id)
left outer join
(select *
from ld_test.dim_address
where ds = '20230101') addr
on (ord.delivery_address_id = addr.address_id)
left outer join
(select *
from ld_test.dim_region_lvl3 --Original city hierarchy dimension table, role name: dim_city
where ds = '20230101') city
on (addr.city_id = city.region_lvl3_id)