DB2 derived Table key knowledge Points you need to learn

Derived Table in DB2 you can call as a temporary table. When the main query ends, the derived table also ends. With SELECT statement, you can create a derived table.

Key Interview Points on Derived Table

  • Exists only within a query
  • Materialized by a SELECT Statement inside a query
  • Space comes from the user’s space
  • Deleted when the query ends

SQL Query

select *
(select avg(salary) as avg_salary from employee_table)
as sriniderived;

Here, sriniderived is the derived Table.

The avg_salary is the column name. The query inside the ‘()’ is called SELECT statement for derived table.

derived table in DB2 works within the query.

SQL Query for Derived Table in Other way

with sriniderived(avgsal) as
(select avg(salary) from employee_table)
select *

The name with clause is “sriniderived” you can call it as derived table.

The SQL query with select statement in “()” is for dervied table. That means derived table will form here.

Next you need to give SELECT * statement to retrieve the data.

Related Posts

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.