Sql union help

Please help.

I have a Select statement pulling all fields A,B,C,D,E from TABLE Z

I have another SELECT Statement pulling from same TABLE Z. But only pulling those that field B = "BAC", "DAS" by creating a new column to differentiate this filter that states " 1 IS BAC". So, if it's BAC or DAS, it shows 1.

I'm thinking a UNION. I need help to writing the correct UNION and WHERE statement

SELECT A,B,C,D,E
FROM Z
LEFT JOIN Z.das
ON Z.key = R.key

SELECT A,B, C,D,E,
1 AS BAC
FROM Z
LEFT JOIN Z.das
ON Z.key = R.key

WHERE B in ("BAC", "DAS")

Maybe:

SELECT A,B,C,D,E
	,CASE WHEN  B in ('BAC', 'DAS') THEN 1 ELSE 0 END AS BAC
FROM Z;

Otherwise please read the following:

1 Like