jeudi 3 septembre 2015

Please help select case join

I am trying to some sql code that combines information from 2 tables and uses case but it is not returning all the data. Would someone be so kind as to help.

SELECT TABLE1.PRODUCT, TABLE1.TYPE, TABLE1.AMOUNT,
(CASE
  WHEN TABLE1.PRODUCT = 'RADIO'
    THEN 100
  ELSE 200
  END) AS PRODUCT_CODE,
(CASE
  WHEN TABLE1.TYPE = 'NEW'
     THEN 'Y'
  ELSE TABLE2.AGE
  END) AS STATUS
FROM TABLE1 LEFT JOIN TABLE 2 ON TABLE1.TID = TABLE2.TID
WHERE TABLE1.DATE > '01-AUG-15'
AND TABLE2.DATE = '02-AUG-15'

The problem I am having is that I need all records from table1 and those that apply from table2 but when the query is returning less rows than there are in table 1. Please please help.

Aucun commentaire:

Enregistrer un commentaire