Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

query problem

 
vamshi g
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all how to retrive data using firstname or lastname.
when a user enters his firstname or lastname he will get all the details about him,but i dont know how to write or(||) in the query,
my query is:
select url,title,user_id from user_profile where first_name='vamshi'|| last_name='g'

is this query is correct.
thank you.
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In Java, OR = ||
In SQL, OR = OR

[great minds think alike]
[ September 19, 2008: Message edited by: Jan Cumps ]
 
vamshi g
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i give the firstname or lastname i want to get the records using firstname or lastname,can you give me the query please.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vamshi,
Jan gave you the query. Just substitute the word "or" where you have "||".
 
vamshi g
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,that is not working,if i enter either firstname or lastname i want to get the result.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are saying you never know whether user inputs Firstname or Lastname. In that case you need seperate queries to match firstname and lastname. If user enters firstname go for one query else go for the other.

where first_name='vamshi' OR last_name='g'


using this would give you all the matching rows either firstname or lastname thats may not what you want.
 
vamshi g
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thanks for your reply,so i need to write another query,
cant i write in one query.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vamshi g:
cant i write in one query.

No. What's the problem with using two queries?
 
vamshi g
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
select user_id from user_profile where (first_name||' '||last_name) like 'SACHEEN'


is this is correct,am getting no records with this query,what is the problem any one explain me.

if i give select user_id from user_profile where first_name like 'SACHEEN'

it is working.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try:

like '%SACHEEN%'


this will match the word "SACHEEN" anywhere in the string you are looking for.
 
vamshi g
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i got the solution,
thanks for replies.

this is my query its working,

select user_id from user_profile where first_name like 'SACHEEN' or last_name like 'ANVEKAE'
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic