Forum Moderators: coopster

Message Too Old, No Replies

Unknown column '#*$!' in 'where clause' error

I need help rewriting a SQL statement

         

dainstructor

7:14 pm on Mar 30, 2007 (gmt 0)

10+ Year Member



For some reason I am recieving this error while trying to pull data from a customer database. The crazy thing is it only happens while trying to pull employees with both letters and numbers in their employee id. I wasn't sure what was causing it so I searched this site and found a similar thread:

[webmasterworld.com...]

This thread recommends not combining comma joins and left joins as I am with my search. The statement I have is below:


mysql_select_db($database_master_user, $master_user);
$query_getAssignment = "SELECT *, projects.projectName FROM assignments LEFT JOIN projects USING (projectID) WHERE assignments.empNo =".$employeeNo . " ORDER BY assignments.projectID";

Can someone help me phrase this so that I do not need to mix comma and inner joins? Or does anyone know of another way around this problem?

Thanks in advance,

ericjust

7:25 pm on Mar 30, 2007 (gmt 0)

10+ Year Member




$query_getAssignment = "SELECT *, projects.projectName FROM assignments LEFT JOIN projects USING (projectID) WHERE assignments.empNo ='".$employeeNo . "' ORDER BY assignments.projectID";

Use '' around the employeeNo.

dainstructor

7:36 pm on Mar 30, 2007 (gmt 0)

10+ Year Member



Thanks for the reply. I'm still getting the unknown column error however.

joelgreen

8:04 pm on Mar 30, 2007 (gmt 0)

10+ Year Member



try replacing

USING (projectID)

with

ON assignments.projectID = projects.projectID

If does not help, try replacing this
SELECT *, projects.projectName

with just
SELECT *

dainstructor

8:29 pm on Mar 30, 2007 (gmt 0)

10+ Year Member



Thanks for the help.

Still not quite working.

justgowithit

8:43 pm on Mar 30, 2007 (gmt 0)

10+ Year Member



Post the error and the query

joelgreen

11:03 pm on Mar 30, 2007 (gmt 0)

10+ Year Member



Any indices exist for assignments.projectID or projects.projectID?

Maybe indices type does not match. Just a guess.

Also try replacing this
WHERE assignments.empNo =".$employeeNo . " ORDER BY assignments.projectID";

with this
WHERE assignments.empNo = '".$employeeNo . "' ORDER BY assignments.projectID";

Adding quotes will not hurt. Also remember to escape $employeeNo with mysql_real_escape_string