How to select from multiple tables, map to 1 object
How to select from multiple tables, map to 1 object
18205-Sep-2023
Updated on 06-Sep-2023
Home / DeveloperSection / Forums / How to select from multiple tables, map to 1 object
How to select from multiple tables, map to 1 object
Aryan Kumar
06-Sep-2023To select from multiple tables and map them to an object, you can use the Join and the Select operator. The
Join
operator join the tables and theSelect
operator associates the rows of the joined tables to an object.The join operator has the same syntax as previously described. The syntax for the select operator is:
where
column1
andcolumn2
are the names of the columns that you want to map to the object.For example, the following code joins the tables
Customers
andOrders
and maps the rows to a single object namedCustomerOrder
:This code returns a new table that containing the names of all the customers and the IDs for all the orders. Each row in the new table will be an object of the
CustomerOrder
type.You can also use the
Select
operator to map the rows of the joined tables to another object. For example, the following code joins theCustomers
,Orders
, andProducts
tables and maps the rows to a single object calledCustomerOrderProduct
:This code returns a new table containing the names of all the customers, their order IDs, and the names of all the products they ordered. Each row of the table is an object of the
CustomerOrderProduct
type.