Results 1 to 8 of 8

Thread: SQL Statement

  1. #1
    Join Date
    Jan 2004
    Posts
    18

    Unanswered: SQL Statement

    This is what I'm trying to do:
    "Select * from Employees WHERE ID = AAFC.EmployeeID"

    Does anyone know how I should write this, because this doesn't seem to be working.

    Thanks

  2. #2
    Join Date
    Jan 2003
    Location
    India
    Posts
    523
    Quote Originally Posted by Gazzou
    This is what I'm trying to do:
    "Select * from Employees WHERE ID = AAFC.EmployeeID"

    Does anyone know how I should write this, because this doesn't seem to be working.

    Thanks
    select e.* from employees e ,aafc a where e.ID=a.EmployeeId

  3. #3
    Join Date
    Jan 2004
    Posts
    18
    Thanks, That was exactly what I was looking for.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    AAAACK!!!

    Use a JOIN, please!

    select employees.*
    from employees
    inner join aafc on employees.ID = aafc.EmployeeID
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Jan 2004
    Posts
    18
    What advantages I have in doing a JOIN instead of a simple select?

  6. #6
    Join Date
    Oct 2003
    Posts
    84
    for one, they are a lot easier to read...

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    A JOIN is a simple select. It's the simplest, as a matter of fact. If you have a complex query with many linked tables, throwing all the links into the WHERE clause at the end makes the code very difficult to read.

    Also, the optimizer is much more likely to use indexes on JOINs than on WHERE relationships. For simple statements the optimizer will convert the WHERE syntax into a JOIN prior to execution, but for complex statements it may not be able to do so.

    Code like a pro. Use JOINs to link tables. Use the WHERE clause to filter table records.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  8. #8
    Join Date
    Jan 2004
    Posts
    18
    Thanks Blindman, I'll start coding that way.

Posting Permissions

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