Search code examples
mysqljoinmysql-error-1064

MySQL Join question


I'm setting up a small system that keeps track of which person is assigned to a request.

My table structure looks like this:

Table: requests

  • RequestID
  • RequestDetails

Table:request_staff

  • RequestID
  • StaffUserID

Obviously RequestID is used to link to the two tables.

I want to select all requests for a staff member. My understanding is that a join would be the best method...

SELECT *
FROM `request_staff`,`requests`
WHERE 'RequestID'.`request_staff` = 'RequestID'.`requests`;

I'm getting an error message of:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.request_staff = 'RequestID'.requests' at line 3

Thanks for your help!


Solution

  • I think you should try it like this:

    SELECT *
    FROM `request_staff`,`requests`
    WHERE `request_staff`.'RequestID' = `requests`.'RequestID';
    

    You had the field and table names reversed.