• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

query problem

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,that is not working,if i enter either firstname or lastname i want to get the result.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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'
 
reply
    Bookmark Topic Watch Topic
  • New Topic