I have this Query that takes at least 1 minute to run. It uses a lot of Left Joins. Is there any way to make it faster ? I'm new to SQL, so help would be appreciated.
SELECT
distinct cnt.last_name,
cnt.bus_ph_num,
cnt.email_addr,
usr.login,
cnt.fst_name,
cnt.fk_id
from
contact cnt
LEFT JOIN
transaction tran
ON tran.id=cnt.fk_id
left join
party party
on party.pk_id=cnt.fk_id
left join
user usr
on usr.fk_id=cnt.fk_id
left join
role role
on
usr.role_id = role.pk_row_id
where
cnt.status_cd=1
and party.fk_id= 'xyz'
and (
usr.login like '%somevalue%'
and (
tran.txn_trk_num is null || tran.txn_trk_num like '%somevalue%'
)
and cnt.last_name like '%somevalue%'
and cnt.email_addr like '%somevalue%'
and cnt.busin_ph_num like '%somevalue%'
)
and (
tran.txn_trk_num is null || tran.txn_typ=1 || tran.txn_typ=2 || tran.txn_typ=3
)
and (role.role_name ='ROLE_ADMIN')