(a) Write a SELECT command that returns two columns from the General Ledger_Acco
ID: 3729401 • Letter: #
Question
(a) Write a SELECT command that returns two columns from the General Ledger_Accounts table, namely, account number and account description. The purpose is to identify each distinct account number that has never been used in an invoice (via an invoice line item). The order of the resulting list should be by account number. It will be helpful to use a subquery and the NOT EXISTS operator for this command. (b) Then write two result dataset rows of sample data that might be retrieved by the query. What is actually retrieved depends on what is in the table. The data you write does not have to match any data that is actually in our sample tables The table structures are also shown for information Table: invoice line items Column Name invoice id invoice sequence NUMBER account numberNUMBER line item amt line item description VARCHAR2(100) No Data Type NUMBER Nullable Default Data Constraint No No No No PK,FK PK FK NUMBER(9,2) Table: general ledger accounts Column Name Data Type Nullable Default Data Constraint number No PK account description varchar2(50) No UNIQUEExplanation / Answer
Answer:
Screenshot:
Select Query:
Select account_number, account_description from general_ledger_accounts
Where NOT EXISTS (Select * from invoice_line_items where invoice_line_items.account_number = general_ledger_accounts.account_number)
Order by account_number;
Explanation: In the above query, the subquery tries to retrieve data from invoice_line_items and general_ledger_accounts tables where matching entries are present. The NOT EXISTS keyword outside the subquery picks up all account numbers which doesn't exist in the sub query.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.