• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Alias a field name in a join query

Participant ,
Jun 17, 2013 Jun 17, 2013

Copy link to clipboard

Copied

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?

Views

602

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jun 17, 2013 Jun 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

Votes

Translate

Translate
Enthusiast ,
Jun 17, 2013 Jun 17, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 17, 2013 Jun 17, 2013

Copy link to clipboard

Copied

LATEST

Should be

ON employee_passwords.Employee_ID=employee_general_info.[Employee ID]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation