I want to optimize the below DB selection query
select * from
table_name
where
(title=? and grade =?)
or
(title=? and debt =? and grade =?)
or
(prog=? and title = ? and debt =?)
CodePudding user response:
you can use case below way as alternative
select * from
table_name
where
1 = case
when title=? and grade =? then 1
when title=? and debt =? and grade =? then 1
when prog=? and title = ? and debt =? then 1
else 0
end
Just give a try and make sure all are indexed.