Link to home
Start Free TrialLog in
Avatar of Kyle Hamilton
Kyle HamiltonFlag for United States of America

asked on

need SQL query advice on cross referencing three tables

I'm trying to lear SQL. I'm a total noob, please bear with me.

I have these two queries, both of which work, but I'm hoping to get some advice as to which is preferable, or if there is a better way of doing it.

SELECT AVG(price) AS PriceAverage FROM bib inner join (SELECT sub.subcode, accno FROM sub inner join indx on sub.subcode = indx.subcode where subject = 'SOCIAL CHANGE')A on bib.accno = A.accno;

Open in new window



SELECT AVG(price) AS PriceAverage FROM bib inner join (select accno,subcode from indx where subcode in ( select subcode from sub where subject = 'SOCIAL CHANGE'))A on bib.accno = A.accno;

Open in new window


Basically, I have to cross reference three tables to get the info  I'm looking for.

Thanks in advance, and apologies for any cringe factor...
Kyle
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kyle Hamilton

ASKER

That looks so much better, thank you!

Best,
Kyle
:) no problem. cheers. Paul