views:

38

answers:

3

Hi,

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!

+1  A: 
SELECT *
FROM request_staff, requests
WHERE request_staff.RequestID = requests.RequestID;
twerq
Thanks for your help!
Matt
+1  A: 

You have the fields/tables backwards in your where statement. Should be request_staff.RequestID = requests.RequestID

GrandmasterB
Thanks for your answer!
Matt
+2  A: 

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.

FrustratedWithFormsDesigner
Thanks for the quick answer!
Matt