SQL (LibreOfficeBase) How to perform logic function between two columns

38 Views Asked by At

I'm attempting to filter a table by the comparison between two columns. For instance, imagine the table Student with column TestPassed and the table Course with the requirement on the test.

Given the following view:

id.Course id.Student     Course.TestRequired Student.TestPassed
1         66             True                True
2         66             False               True
...
99        52             True                False
100       32             False               False

I would like to filter such a table by performing an NOT(XOR) between condition and student's data (i.e. both true and both false). The results would be:

id.Course id.Student        Course.TestRequired Student.TestPassed
1         66                True                True
2         52                False               True
69        32                False               False

Is it possible in SQL? I did something like this. But how to extend it to general logic expression?

SELECT "IdCourse", "IdStudent", "TestRequired", "TestPassed" ,
       CASE WHEN "TestRequired" = "TestPassed" THEN 'YES'
       ELSE 'NO' 
       END AS Results
FROM "Filter_Partecipant_Course_byTestRequired"
1

There are 1 best solutions below

0
On

If you want to select only the different results, a guess a WHERE clause should do it:

Select IdCourse, IdStudent, TestRequired, TestPassed
FROM Filter_Partecipant_Course_byTestRequired
WHERE TestRequired <> TestPassed

This way, If one of the value is true, then the other one has to be false to be returned