0

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

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by rch1231
1

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.