Monicka Akilan Monicka Akilan - 1 year ago 58
MySQL Question

Excluded row based on a another table cell value in mysql

I have two tables.

student master
enter image description here
enter image description here
I executed the query

SELECT f.standard,fee_type,fee_name,amount,ac_year FROM fee_master f, student_master s
s.standard=f.standard and

I got resultset like
enter image description here

But my need is
if studnet_master.ac_year==AC16 then INITIAL FEE should get removed from resultset or if studnet_master.ac_year==!=AC16 then ADMISSION FEE should get removed from resultset

Can anyone please help me to sort out this....

Thanks in advance...

Answer Source

Just add two extra conditions to your WHERE clause:

SELECT f.standard, f.fee_type, f.fee_name, f.amount, s.ac_year
FROM fee_master f
student_master s
    ON s.standard = f.standard
WHERE s.admission_no = '21300' AND
    (s.ac_year != 'AC16' OR f.fee_name != 'INITIAL FEES') AND
    (s.ac_year = 'AC16' OR f.fee_name != 'ADMISSION FEES')