1

Getting error stating between operator without an and but I have an and so I don't understand. Thank you in advance

Syntax Error

A picture of the question

select 
    a.student_name, a.test_score, b.letter_grade
from 
     sec1311_student_scores a 
inner join
     sec1311_grade_ranges b on a.testscore between b.beginning_score and b.endingscore
order by 
    a.student_name;
5
  • 2
    that's quite a strange syntax error message Commented Nov 7, 2016 at 21:04
  • That's some serious code-fu to achieve that message. Are beginning_Score or ending_score null? odd that one has a _ and one doesn't... are the "Scores" both numeric datatypes? could you need to coalesce(b.beginning_score,0) and coalesce(b.endingscore,0)? or should the last score always be 100 or something? Commented Nov 7, 2016 at 21:05
  • 1
    What RDBMS are you using? Some (like maybe Access) may want the z BETWEEN x AND y clause to be enclosed in parentheses (z BETWEEN x AND y) Commented Nov 7, 2016 at 21:08
  • should the ON statement link student_scores and grade_ranges? Commented Nov 7, 2016 at 21:10
  • Yes i am using access and the datatypes are numbers Commented Nov 7, 2016 at 21:13

2 Answers 2

2

Access does not support BETWEEN in join clauses. From the documentation:

FROM table1 INNER JOIN table2 ON table1.field1 compopr table2.field2
The INNER JOIN operation has these parts:

Part           | Description 
----           | -------------
table1, table2 | The names of the tables from which records are combined.
field1, field2 | The names of the fields that are joined. If they are not numeric, the fields must be of the same data type and contain the same kind of data, but they do not have to have the same name.
compopr        | Any relational comparison operator: "=," "<," ">," "<=," ">=," or "<>."

You can, however, specify multiple join conditions, so you should be able to do:

select 
    a.student_name, a.test_score, b.letter_grade
from 
     sec1311_student_scores a 
inner join
     sec1311_grade_ranges b on a.testscore >= b.beginning_score 
                        and on a.testscore <= b.endingscore
order by 
    a.student_name;
Sign up to request clarification or add additional context in comments.

2 Comments

You are right Access doesnt support BETWEEN in the ON clause. And just for the sake of being accurate : this is usually called a non equi-join
it doesnt work still with the new code either. but thanks for the info on the between
1

Try with this:

select 
    a.student_name, a.test_score, b.letter_grade
from 
    sec1311_student_scores as a, 
    sec1311_grade_ranges as b 
where
    a.testscore between b.beginning_score and b.ending_score
order by 
    a.student_name;

2 Comments

That works but i was asked to write what you just wrote with a inner join instead of the where clause. Thank you for your effort though it is greatly appreciated
You can be asked many things, sometimes the impossible but, in Access SQL, this is the method. It is even displayable in the GUI designer which some join methods not are.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.