Avatar of Kyle Hamilton
Kyle Hamilton
Flag 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
DatabasesSQL

Avatar of undefined
Last Comment
PortletPaul

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
PortletPaul

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kyle Hamilton

ASKER
That looks so much better, thank you!

Best,
Kyle
PortletPaul

:) no problem. cheers. Paul
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes