Query:
where (table1.subject_1 like '%TEST1%' OR
table1.subject_1 like '%TEST2%' OR
table1.subject_1 like '%TEST3%' OR
table1.subject_1 like '%TEST4%'
)
OR
(table1.subject_2 like '%TEST1%' OR
table1.subject_2 like '%TEST2%' OR
table1.subject_2 like '%TEST3%' OR
table1.subject_2 like '%TEST4%'
)
Here if subject_1 = TEST1 then no need to search for the remaining conditions, if not found then search for the other conditions.
I need a record having either of subject_1 from the above query. If subject_1 does not match with any of the results then search for subject_2.
My problem: from the above query, multiple records are being returned where subject_1 matches TEST1 and TEST2 both.
Example:
no, name, add1, occ, date, subject_1,subject_2,Exclusion_number
-----------------------------------------------------------------------------
446 REBECCA street1 Y 1/1/2001 TEST1 AB 10
446 REBECCA street1 Y 1/1/2001 TEST2 A 11
I should be able to fetch one row as subject_1 like '%TEST1%' match found. I should not get the second row, as the first condition satisfied already.
Currently with my query, I am getting 2 rows, where the requirement is to get only one row.
In case first condition fails then I should check the second condition subject_2 like '%TEST2%'.