Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left join with where clause for right table (Must return NULL from right) - Oracle

I have 2 tables ID and Comm. The tables are as follows

 
ID                          
AppID   Name
1       James
2       John
.
.
100     Jeff

Comm
AppID  Comment
1      abc
1      def
1      pqr
2      abc
2      def
2      pqr
3      def

I want all appID from ID (First table) and from Comm(Second table) I want only those comment which are equal to abc, rest others should be NULL.

I am using following query, not sure how do I filter comment abc and Null

select id.appid,comm.comment
from id left join comm on
id.appid=comm.appid
where comm.comment = 'abc'

I know I have the logic wrong, trying to figure out where should I change. Any help is appreciated.

like image 311
Rahul Gupta Avatar asked Oct 12 '25 06:10

Rahul Gupta


1 Answers

select id.appid,comm.comment
from id 
left join comm 
    on id.appid=comm.appid
    and comm.comment = 'abc'
like image 146
Lennart Avatar answered Oct 14 '25 20:10

Lennart