Home > OS >  How do i get 2 query from different table?
How do i get 2 query from different table?

Time:07-22

I tried using

SELECT segment_name, (select num_rows from all_tables
where tablespace_name='TPCHR'), blocks, extends, bytes 
from dba_segments where tablespace_name='TPCHR'

but i am getting single-row subquery returns more than one row.

Question

Not sure what I am doing wrong, I am trying to select the require columns in a table.

CodePudding user response:

Just join the tables:

SELECT segs.segment_name, tbls.num_rows, segs.blocks, segs.extents, segs.bytes 
  FROM dba_segments segs
       INNER JOIN all_tables tbls ON segs.segment_name = tbls.table_name
 WHERE segs.owner        = 'TPCHR' 
   AND segs.segment_type = 'TABLE';
  •  Tags:  
  • sql
  • Related