Results 1 to 2 of 2

Thread: Error Query

  1. #1
    Join Date
    Jun 2008
    Posts
    3

    Unanswered: Error Query

    I have one table (tbl_employee) with many relations (tbl_relation), you can see it below :
    ---------------------
    SELECT
    tbl_employee.NAME,
    tbl_employee.DATEOFBIRTH,
    tbl_relation.CODEDESC
    FROM
    tbl_employee
    INNER JOIN tbl_relation ON (tbl_employee.GENDER = tbl_relation.CODENAME)
    AND (tbl_employee.INTEREST = tbl_relation.CODENAME)
    AND (tbl_employee.YEARIN = tbl_relation.CODENAME)
    WHERE
    (tbl_relation.CODE = '01') AND
    (tbl_relation.CODE = '02') AND
    (tbl_relation.CODE = '03')
    -------------------------------------------------
    I have an error when I execute my query.
    Is my query correct? Help me, please ..

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    an error, eh?

    perhaps you might share with us what that error was

    in any case, the query will not produce any results

    the WHERE clause specifies that each tbl_relation.CODE value must be equal to three different values at the same time

    clearly, this is impossible

    however, if you change the ANDs to ORs, then the WHERE clause makes sense

    but the ON clause of the join suffers from the same problem

    you want tbl_relation.CODENAME to be equal to three different tbl_employee column values

    clearly, this is only possible when those three values are all equal to each other

    and GENDER = INTEREST = YEARIN, while not strictly impossible, doesn't make much sense either
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •