Skip to main content
Announcements
YOUR OPINION MATTERS! Please take the Qlik Experience survey you received via email. Survey ends June 14.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to write a subquery with "if else" condition

Hi friends,

I have the following SQL query:

select

case when (select id from table1 where id=number) is null then 'Not Exists'

         else 'Exists'

END case,

number,name from table2;

I have created 2 QVD files with table1.qvd and table2.qvd.

I knew only this:

Load number,

        name

FROM

(qvd);

Any help is greatly appreciated.

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

HI,

Try this

Table1:

LOAD

     id

FROM Table1.QVD;

LEFT JOIN (Table1)

LOAD

     Number as id,

     Name

FROM Table2.qvd;

Data:

LOAD

     id,

     Name,

     If(IsNull(Name), 'Not Exists', 'Exists') AS Status

RESIDENT Table1;

DROP TABLE Table1;

Hope this helps you.

Regards,

Jagan.

View solution in original post

4 Replies
phaneendra_kunc
Partner - Specialist III
Partner - Specialist III

Try this

Table1:

Load id as number

FROM

(qvd);

Table2:

Load if( exists(number),'Exists','NotExists') as XXXX,

        name

FROM

(qvd);

jagan
Luminary Alumni
Luminary Alumni

HI,

Try this

Table1:

LOAD

     id

FROM Table1.QVD;

LEFT JOIN (Table1)

LOAD

     Number as id,

     Name

FROM Table2.qvd;

Data:

LOAD

     id,

     Name,

     If(IsNull(Name), 'Not Exists', 'Exists') AS Status

RESIDENT Table1;

DROP TABLE Table1;

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

thank you phaneendra

Not applicable
Author

thanks jagan mohan. It worked.