Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected output in Oracle SQL

On executing the query

select * from employee
where salary <= previous_salary

I'm getting a wrong output as follows (it's returning the entire table). I'm doing this in Oracle Application Express Edition

ID  NAME    SALARY  DEPT    PREVIOUS_SALARY
1   nadeem  1000    10      1500
2   kutu    1000    10      1500
3   aisha   1500    20      500
4   aisha   1500    20      500

and on executing this query

select * from employee
where salary >= previous_salary

I get no data found.

like image 924
user1129400 Avatar asked Dec 01 '25 08:12

user1129400


1 Answers

You've probably used a CHAR or VARCHAR2 type for the SALARY and PREVIOUS_SALARY columns.

When compared as strings, the data should work as you claim it does.

If you change the columns containing numbers to a numeric type, then the numeric comparisons will work as you intended.

like image 75
Jonathan Leffler Avatar answered Dec 04 '25 01:12

Jonathan Leffler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!