I have this statement in my SELECT:
b.major1 || ',' || b.major2 || ',' || b.minor

But I really want to only concatenate IF b.major2 is not null or b.minor is not null. I was able to partially do it with CASE, but I've not been able to make it work otherwise.

Can you help me get this done with IF? Is there a good tutorial to use so that I don't post these simple questions?


Here's the whole query:

SELECT
a.passport_listing_id
,a.passport_registration_id
,coalesce(b.email, c.email) email
,coalesce((b.major1), c.dept) major
,CASE
WHEN b.major2 is not null THEN b.major1 || ', ' || b.major2
END as a_major

,e.passport_survey_id
,f.title
,f.start_date
FROM passport_registration a
Left outer join students b
On a.student_id = b.student_id
Left outer join people c
On a.people_id = c.id
Left outer join passport_attendance d
On a.passport_listing_id = d.passport_listing_id
and a.s_uid = d.s_uid
Left outer join passport_survey e
On a.passport_listing_id = e.passport_listing_id
and a.s_uid = e.s_uid

Left outer join passport_listing f
On a.passport_listing_id = f.passport_listing_id

WHERE a.s_uid = #s_uid#