Reputation: 5
I have a question in a question book but I'm stuck:
Q: Table DebtPayment_DL
in database PaymentLoad
needs a subset of information extracting to display DebtAccountReferences
which have a PaymentStartDate
after 01/01/2021
and no close date.
The schema:
[DebtAccountReferences] - varchar(50) not null
[PaymentStartDate] - datetime, not null
[CloseDate] - Datetime, not null
My attempt:
SELECT *
FROM DebtPayment_DL
WHERE PaymentStartDate > 01/01/2021 AND CloseDate IS NULL
Now do I need a join statement as well to join the table DebtPayment_DL
with DebtAccountReferences
? Also if this is wrong please correct me.
I'm not exactly sure what the result is, I don't think there's a specific result just a vivid idea.
Upvotes: 0
Views: 34
Reputation: 15905
There should not be any joining since the information is available in that table. Instead of selecting all the columns you can select only DebtAccountReferences as required.
select DebtAccountReferences
from DebtPayment_DL
where PaymentStartDate > '01/01/2021' and CloseDate is null;
Upvotes: 1
Reputation: 19
Based on the information you have given, you do not need a join statement. All of the information you need is stored in the table 'DebtPayment_DL'
Your code is therefore correct and should generate the correct output.
Upvotes: 0