|
-
May 2nd, 2007, 12:32 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] select statement 2 tables
SELECT avg(tblData.MV), tblStandard.MV_MIN FROM tblData, tblStandard WHERE tblData.COMPOUND_NO='123'
i've got this error:
"you try to execute a query does not include the specified expression 'MV_MIN
as part of an aggregate function.'"
above code would select/compute the average of tblData.MV
and list tblStandard.MV_MIN, when i try to remove avg() and remain the tblData.MV no error found.
any idea?
tnx
Last edited by Hack; May 2nd, 2007 at 05:51 AM.
Reason: Added RESOLVED to thread title and green resolved checkmark
-
May 2nd, 2007, 12:48 AM
#2
Thread Starter
Hyperactive Member
Re: select statement 2 tables
sorry i already solved this one.
i found on the net using subquery
SELECT avg(tblData.MV) as ave, (SELECT tblStandard.MV_MIN FROM tblStandard WHERE COMPOUND_NO='123' ) as min FROM tblData WHERE COMPOUND_NO='123'
-
May 2nd, 2007, 02:54 AM
#3
Fanatic Member
Re: select statement 2 tables
SELECT avg(tblData.MV), tblStandard.MV_MIN FROM tblData INNER JOIN tblStandard ON tblData.COMPOUND_NO = tblStandard.COMPOUND_NO WHERE tblData.COMPOUND_NO='123' GROUP BY tblStandard.MV_MIN
- You should use a join to link your tables. Now it Links all rows from the two tables with eachother. Linking tables should be quicker that executing a sub-query per record.
You should use group by. In this exapmle you group by the field tblStandard.MV_MIN. This means it calculates the average of tblData.MV per value of tblStandard.MV_MIN.
- Use the thread tools to Mark your Thread as Resolved when your question is answered.
- Please Rate my answers if they where helpful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|