Machine-translated by Google. Questions are authored in English.
Top

Discussion

For the SQL query given below :

SELECT employee_name
FROM employee
WHERE salary BETWEEN 70000 and 130000

Select the equivalent in SQL without BETWEEN operator :

  • A.SELECT employee_name FROM employee WHERE salary \(\gt\) 70000 and salary \(\lt\) 130000
  • B.SELECT employee_name FROM employee WHERE salary = 70000 and salary = 130000
  • C.SELECT employee_name FROM employee WHERE salary \(\gt\)= 70000 and salary \(\lt\)= 130000
  • D.SELECT employee_name FROM employee WHERE salary \(\lt\) 70000 and salary \(\gt\) 130000

Answer: C

The equivalent query uses salary \(\gt\)= 70000 and salary \(\lt\)= 130000.

SQL's BETWEEN is inclusive: salary BETWEEN 70000 and 130000 is true for 70000 and for 130000 as well as for every value between them. So the rewrite needs greater-than-or-equal and less-than-or-equal.

Option A uses strict inequalities and drops the two end values. Option B asks for a salary equal to both numbers at once, which no row satisfies, and option D asks for a salary below 70000 and above 130000 together, which is also impossible.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.