skip to Main Content

Example:

I want the COL3 replaced with the Select statement form TABLE B as below in my original Select Statement of TABLE A:

Select COL1, COL2, <*COL3*> from TableA;

COL3 => (Select Sum(COL2) from TableB Group by COl1 and order by COL1)

2

Answers


  1. You could try using some subqueries

    select t2.col1, t1.col3, t3.col2
    from TableA t2
    inner join  (
        Select col1, Sum(COL2) col3 
        from TableB Group by COl1 and order by COL1
    from TableA ) t1 on t1.col1 = t2.col1
    inner join (
         select col1, col2
    ) t3 on t3.col1 = t2.col1
    
    Login or Signup to reply.
  2. You can use joins, if you have something common between the two tables.
    For example:

    SELECT T1.COL1, T1.COL2, 
    T2.COL3 FROM T1 
    INNER JOIN
    (SELECT COL3 FROM T) T2
    ON T1.COL1 = T2.COL3
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search