how do i simplify the below my sql query

srikotesh
srikotesh used Ask the Experts™
on
Hi Experts,

can some one suggest me alternative or condition in the below query.
i want to convert this query to hibernate hql query.

e.uid like '%SSL%' OR e.title like '%SSL%' OR e.description like '%SSL%' OR e.customkeywords like '%SSL%' OR t.kb_entry_attributes LIKE '%SSL%')

query:
======
select t.id,t.name FROM entry_attributes t  
INNER JOIN entry as e ON (t.kb_id=e.id) AND (e.uid like '%SSL%' OR e.title like '%SSL%' OR e.description like '%SSL%' OR e.customkeywords like '%SSL%' OR t.kb_entry_attributes LIKE '%SSL%')
LEFT OUTER JOIN entry_source es ON (es.kb_id=e.id) AND (es.ticket_id=0)

thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I think this is simpler.
select t.id,t.name 
FROM entry_attributes t  
INNER JOIN entry as e ON (t.kb_id=e.id)
LEFT OUTER JOIN entry_source es ON (es.kb_id=e.id) 
WHERE es.ticket_id=0
AND (e.uid like '%SSL%' 
  OR e.title like '%SSL%' 
  OR e.description like '%SSL%' 
  OR e.customkeywords like '%SSL%' 
  OR t.kb_entry_attributes LIKE '%SSL%')

Open in new window

Author

Commented:
I have to remove that or condition
after and condition or is there multiple times
because of or condition iam unable to change sql query to hql hibernare
is there any alternative for or condition
PortletPaulEE Topic Advisor
Most Valuable Expert 2014
Awarded 2013

Commented:
Mark, that is not an equivalent query

original
LEFT OUTER JOIN entry_source es ON (es.kb_id=e.id) AND (es.ticket_id=0)

If you move this (es.ticket_id=0) condition into the where clause you override the left join and form an "implied inner join" you have to also allow for NULL to preserve the left join, like this

WHERE ( es.ticket_id=0 OR es.ticket_id IS NULL )
EE Topic Advisor
Most Valuable Expert 2014
Awarded 2013
Commented:
srikotesh,
You can put most of the conditions into the where clause as Mark has suggested

select t.id,t.name
FROM entry_attributes t  
INNER JOIN entry as e ON t.kb_id=e.id
LEFT OUTER JOIN entry_source es ON e.id=es.kb_id AND es.ticket_id=0
WHERE (e.uid like '%SSL%'
  OR e.title like '%SSL%'
  OR e.description like '%SSL%'
  OR e.customkeywords like '%SSL%'
  OR t.kb_entry_attributes LIKE '%SSL%')


But I can see no other way to "simplify" it, you a searching through 5 string columns for %SSL%.
The only method for simplification I can see is to simplify the requirement.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial