Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two queries combined together into a single one

 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone

i am working with springs and hibernates, till now i am able to do all the hqls which are required in my project, but now i am facing a typical task.

the thing is i have a table in which it contain 5 column out which 2 are important for my work(current one), they are FIRST NAME and LAST NAME, till now i used to perform only on FIRST NAME or making use of 'and' in the query in combination of another row.

but now i want to perform the query in such a way that it has to search in both FIRST NAME as well as LAST NAME not FIRST NAME and LAST NAME. it has to return any match of my input for both FIRST NAME and LAST NAME.

can any one help me.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it sounds like you needs a query that compares what the value in one column or another is like.

What have you got written so far?
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i did not understand what you have asked me, but any way the thing is

i am searching on my database table using hibernate for like search(i;e exact match), begins with & contains on FIRST NAME column now i want to perform the same operation on both the columns now with the same input give for the FIRST NAME

not that the hibernate has to search for the matching pattern in the FIRST NAME and then go for the LAST NAME, it has to perform the same operation on both column in a single query
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so you need to know if one column or another is like your test value.

(This is the reason I asked you to show us what you've written so far).
 
binu narayanan
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reddy,

I think this hql will solve the problem

select columnName1, columnName2 from table(hibernateJava file) where

columnName1 like '%"+strYourInput+"%' or columnName2 like '%"+strYourInput+"%';
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
select columnName1, columnName2 from table(hibernateJava file) where

columnName1 like '%"+strYourInput+"%' or columnName2 like '%"+strYourInput+"%';


this hql returns only those two columns. ok let me make it more clear

think this is my hql

fname is named parameter which get set form my input, this returns all the rows that matches the pattern of my input
now another think about another hql

i want both the results by a single hql.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this hql returns only those two columns.

Yup. Thats what happens if you define a select clause in HQL.

I dunno - how loudly can I hint? You need to write a query which checks whether first_name OR last_name is LIKE the value of fname.

 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the thing is just now i have rectified it, i have done the same earlier but found an error but it is not the fault in the hql but the parameter set in dao,
i regret that, i have rectified it myself
but thank you for resolving it.
 
binu narayanan
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now then the problem has been solved you can post the hql so that it will be helpful for others
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@binu narayanan
sorry if you have been expecting this & i have delayed in posting the reply, here is the ans
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic