Skip to main content
Inspiring
June 17, 2013
Answered

Alias a field name in a join query

  • June 17, 2013
  • 2 replies
  • 748 views

I have a database with spaces in the field names (not my fault).

I am having a problem with the query because one of the fileds I am joining on has a space in its name. See bolded text.

SELECT *

FROM employee_passwords

INNER JOIN employee_general_info

ON employee_passwords.Employee_ID=employees.[Employee ID]

WHERE username = '#username#' AND password = '#password#'  

So I get this error message

Error Executing Database Query.

[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid object name 'employees.Employee ID'.

Is there a way to alias the employees.[Employee ID] field?

    This topic has been closed for replies.
    Correct answer Reed_Powell-ttnmOb

    The error is probably from the SELECT * -  try listing all of the fields individually, including the [Employee ID] field.  You can give it a new name to appear in the query results by aliasing it:

         SELECT [employee ID] AS EmployeeID

    but within the query itself you have to use the [Employee ID] syntax.

    -reed

    2 replies

    p_sim
    Participating Frequently
    June 17, 2013

    Should be

    ON employee_passwords.Employee_ID=employee_general_info.[Employee ID]

    Reed_Powell-ttnmObCorrect answer
    Inspiring
    June 17, 2013

    The error is probably from the SELECT * -  try listing all of the fields individually, including the [Employee ID] field.  You can give it a new name to appear in the query results by aliasing it:

         SELECT [employee ID] AS EmployeeID

    but within the query itself you have to use the [Employee ID] syntax.

    -reed