Hi all,

I am trying to get a SQL Server statement to work for a class I am taking on MS SQL Server.
Here is what I am supposed to do;
1) Write a SQL query that joins two tables in the example database and uses BETWEEN to restrict record selection. (Use salary to restrict the data.)

Here is what I typed for the code;

use Dwight_wk2
Select *from employees
Join Job_Titles
WHERE Salary BETWEEN 20000 and 35000 

And the error message I am getting:

****************************************
Msg 156, Level 15, State 1, Line 9Incorrect syntax near the keyword 'WHERE'.
****************************************

Can anybody tell me why I am getting this error?I can't find any info on how to resolve it anywhere.

Thanks in advance.

COY

Hello,

The problem is you are missing the ON that tells the join how to connect the two tables. There has to be a reference field in employees to link it to job titles but your query will look something like this.

use Dwight_wk2
Select * from employees
Left Join Job_Titles on Job_Titles.Job_Title_ID = employee.Job_Title_ID
WHERE employee.Salary BETWEEN 20000 and 35000

You will probably want to change the specific fields you are getting from employee and job_titles so you only get the fields you want to show. Without the tables I am guessing at the names.

use Dwight_wk2
Select 
employees.Lastname
employees.Firstname
employees.salary
job_titles.job_title
from employees
Left Join Job_Titles on Job_Titles.Job_Title_ID = employee.Job_Title_ID
WHERE employee.Salary BETWEEN 20000 and 35000
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.