1

I have a table with columns date, system, hardness, conductivity, tankno.

date        system  cond    hard   tankno

2014-01-04  HT  55.67   2.68    1
2014-01-05  HT  64.67   3.1     2
2014-01-10  HT  54.77   2.44    1
2014-01-10  HT  66.3    3.47    2
2014-01-18  HT  55.63   2.38    1
2014-01-18  HT  65.9    1.44    2
2014-01-24  HT  53.1    1.76    2
2014-01-28  HT  64.53   2.1     1

I want report like this


Date         system    Tank 1 cond   Tank1 Hard      Tank 2 cond  Tank 2hard

2014-01-04    HT            55.67       2.68            NULL        NULL  
2014-01-05    HT            NULL        NULL            64.67       3.1
2014-01-10    HT            54.77       2.44            66.3        3.47
2014-01-18    HT            55.63       2.38            65.9        1.44
2014-01-24    HT            NULL        NULL            53.1        1.76
2014-01-28    HT            64.53       2.1              NULL       NULL

I am using this sql:

select t1.date, t1.cond as tk1cond, t1.hard as tk1hard,
       t2.cond as tk2cond, t2.hard as tk2hard   
from systemvalue t1 left join systemavalue t2 
     on t1.date=t2.date 
     and t2.tankno='2' 
     and  t2.system='HT' 
     and month(t2.date)='01' 
     and year(t2.date)='2014' 
where t1.tankno='1' and t1.system='HT'
      and month(t1.date)='01' 
      and year(t1.date)='2014'

but this return data pertaining to the dates where tankno 1 value is available like this:


Date         system    Tank 1 cond   Tank1 Hard        Tank 2 cond  Tank 2hard

2014-01-04    HT            55.67       2.68               NULL        NULL  
2014-01-10    HT            54.77       2.44               66.3        3.47
2014-01-18    HT            55.63       2.38               65.9        1.44
2014-01-28    HT            64.53       2.1                NULL        NULL

How to modify the sql so as to get the data for all dates

I want all dates from date columns and join it to all tank 1 vlaues and tank 2 values

mansoondreamz
  • 493
  • 1
  • 4
  • 25

1 Answers1

0

Left join works only for all value you have in left, so if you are missing values in left, you would not have anything to show as a result.

You need to use OUTER join to get values from both isles

What is the difference between "INNER JOIN" and "OUTER JOIN"?

Community
  • 1
  • 1
mavarazy
  • 7,562
  • 1
  • 34
  • 60