Reputation: 1
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).
Upvotes: 0
Views: 328
Reputation: 18569
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.
Upvotes: 2