0

Given Table A with columns: ColA1, ColA2, ColA3

And a Table B with columns: ColB1

I want to restrict the data that can be returned from Table A based on data in Table B, like:

ColA1 not in ColB1

Ideally, some way incorporate SQL queries in the filter with select statements

2 Answers 2

0

What you want is

SELECT a.ColA1
, a.ColA2
, a.ColA3

FROM TableA a
  LEFT OUTER JOIN TableB b on b.ColB1 = a.ColA1

WHERE b.ColB1 IS NULL

So...
Query1 contains ColA1, ColA2, and ColA3 from TableA.
Query2 contains ColB1 from TableB.
Query3

  • joins Query1 and Query2 on ColA1 1..1 = 0..1 ColB1
  • Data Items: ColA1, ColA2, ColA3
  • Filter: ColB1 IS NOT NULL
2
  • Would this be in the query subject, or in a standalone filter? In the query subjects, I have added some filters through a where clause, but they seem to not work. They work when running in SQL, as well as when running the Cognos 11 Generated SQL in Oracle, but I am guessing due to joins/links in Framework Manager the where clauses get broken somehow, and thus aren't working Sep 29, 2020 at 7:01
  • I'm guessing you've never used Cognos before? You don't put a WHERE clause in a data item expression. In Cognos, you drag and drop. What I described is creating 2 queries and joining them into a third -- and how to configure the join. The SQL code was for reference in case you think better in SQL code than in Cognos GUI.
    – dougp
    Sep 29, 2020 at 18:14
0

not exists is probably what you are looking for

Try something like this

select * from TableA as T1  
where not exists                                                  
  (select * from TableB as T2         
    where t1.key1 = t2.key1 and T1.key2 = t2.key2)                

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.