Need to know how to rewrite this code and still have it working!! Please help me D:

AS the title states...I really need help on rewriting a line of code but still keeping it working 

CODE:
SELECT C.coCode, C.coName, C.risk, C.curPrice
FROM COMPANY AS C
WHERE C.recom = buy AND C.coCode NOT in
(SELECT H.coCode FROM CLIENTS AS L INNER JOIN HOLDINGS AS H ON L.accountNo = H.accountNo
WHERE L.lastname = sawyer)

I know this is probably a really, really simple and easy code for most but I'm still a beginner at this...I've only learnt this for about 2weeks and our teacher has yet to teach us anything knowledgeable that's currently in my unreasonable assessment which is due in less than 12hours from now...any help would be much appreciated. Thanks! 

March 29th, 2015 8:08am

Have you tried something from your end so far?

Please try:

SELECT C.coCode
	,C.coName
	,C.risk
	,C.curPrice
FROM COMPANY AS C
LEFT JOIN (
	SELECT H.coCode
	FROM CLIENTS AS L
	INNER JOIN HOLDINGS AS H
		ON L.accountNo = H.accountNo
	WHERE L.lastname = 'sawyer'
	) T
	ON C.coCode = T.coCode
WHERE C.recom = 'buy' AND T.coCode IS NULL

Free Windows Admin Tool Kit Click here and download it now
March 29th, 2015 8:26am

To be completely honest with you, I don't even know if it will work or not. We weren't even given a database to test this on, we were just tossed this code and got told to rewrite it in the assessment. It's a petty move from my school but what can I do?...At any rate, I'm just gonna throw it on..that's more likely to be right than anything random written by me, who hasn't yet to even properly learn anything to do with SQL. Thanks for the help tho! I'm just gonna believe in your efforts and hope it works!
March 29th, 2015 9:55am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics