Skip to content
Advertisement

How to ‘create’ NULL data in Teradata SQL for non existing relations

I have 2 tables, one lists features with a feature value that an account might or might not have (TBL_Feat), the other lists the accounts (TBL_Acct).

I’m looking for a query to give me all features for every account, and if the feature doesn’t exist for this account, a line with the feature but with NULL as value. My list of features is fixed, so that’s no concern.

What I’m expecting to see is a result like this:

One adittional question, would anything change to your answer if there is a feature that is not prevalent in the Tbl_Feat table? Eg. FEATURE_ID = 3 in my example here.

Advertisement

Answer

Use a cross join to generate the rows and left join to bring in the values:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement