1

I have a question about how to find salary discrimination based on the employee gender. I have MS Acess 2007 and must use SQL queries to figure it out

Keep in mind, this is after I joined 3 tables together into one multi-table query. Within this query, whenever I want to sort any column with, for example, an ORDER BY Salary, it gives me an error sign saying:

Syntax error (missing operator) in query expression 'Salary'
WHERE JobClass.JobClassID = Employees.JobClassID 
AND Department.DepartmentID = Employees.DepartmentID'.

I want to try to sort more than one column within the query.

Here is the multitable query code in total:

SELECT JobClass.JobClassID, JobClassName, Department.DepartmentID, 
       DepartmentName, LastName, FirstName, Title, Sex, Years, Salary
FROM  JobClass, Employees, Department
ORDER BY 'Salary'
WHERE JobClass.JobClassID = Employees.JobClassID AND Department.DepartmentID = Employees.DepartmentID;
HansUp
  • 95,961
  • 11
  • 77
  • 135

2 Answers2

1

Order by Clause should be come after the where clause

Try like this

SELECT JobClass.JobClassID, JobClassName, Department.DepartmentID, 
       DepartmentName, LastName, FirstName, Title, Sex, Years, Salary
FROM  JobClass, Employees, Department
WHERE JobClass.JobClassID = Employees.JobClassID AND Department.DepartmentID = Employees.DepartmentID
ORDER BY Salary

SLECT SYNTAX

SELECT [predicate] { * | table.* | [table.]field1 [AS alias1] [, [table.]field2 [AS alias2] [, …]]}     
FROM tableexpression [, …] [IN externaldatabase]     
[WHERE… ]    
[GROUP BY… ]     
[HAVING… ]     
[ORDER BY… ]     
[WITH OWNERACCESS OPTION]
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
0

Unless Access '07 completely disregards standard SQL ( and I don't think it does) your SQL Syntax is off.

Instead of putting the ORDER BY before the WHERE clause, it should go after the WHERE.

erik258
  • 14,701
  • 2
  • 25
  • 31