Results 1 to 3 of 3

Thread: [RESOLVED] select statement 2 tables

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Resolved [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

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    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'

  3. #3
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    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
  •  



Click Here to Expand Forum to Full Width