user3382009
user3382009

Reputation: 11

How to sort multiple columns in a multitable query?

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;

Upvotes: 1

Views: 104

Answers (2)

erik258
erik258

Reputation: 16305

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.

Upvotes: 0

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28403

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]

Upvotes: 1

Related Questions