0
  1. Determine the amount of total profit generated by the book purchased on order 1002. Display the book title and profit. The profit should be formatted to display a dollar sign and two decimal places.

ZJLB_ORDERITEMS contains ORDER#, ISBN

ZJLB_BOOKS contains ISNB, TITLE, RETAIL, COST

SELECT ISBN
FROM ZJLB_ORDERITEMS
WHERE ORDER# = '1002';

(then I get an output of 8843172113)

SELECT TITLE,
       TO_CHAR(RETAIL - COST, '$99,999.99') "Profit"
FROM ZJLB_BOOKS,
WHERE ISBN = '8843172113';

(then I get the Title I want)

but I need to combine two scripts together because I can't manually find the ISBN first, then input WHERE ISBN = '8843172113';

Can I first output the value of ISBN found in script to X then in the script 2, Where ISBN= X (previous result).

1 Answer 1

2

You can use JOIN clause:

An SQL join clause combines records from two or more tables in a database

Try this:

SELECT A.ISBN, B.TITLE, TO_CHAR(B.RETAIL - B.COST, '$99,999.99') "Profit"

FROM ZJLB_ORDERITEMS A JOIN ZJLB_BOOKS B

ON A.ISBN = B.ISBN

WHERE A.ORDER# = '1002';

See here for the join concept.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.