compre colums using LIKE operator

Last Post 08 Dec 2008 01:44 PM by leroyl. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
leroyl
New Member
New Member

--
08 Dec 2008 12:22 PM

Hello all,

I am sure this is easy and i am missing somthing simple...

i wouuld like to run a query that will search for any instance of their last name in thier password...

here is my simple table...
all columns are VARCHAR type... well except for the ID column.

ID FName LName Password
----------------------------------------------
1 john smith smith
2 jane doe doe123
3 tiny tim tim%
4 peter parker spideypeter
4 bruce wayne batman


here are the quirest that i have tried

select * from mytable where fname = lanme this returns row 1 as suspected
select * from mytable where fname like lname this returns only row 1
select * from mytable where fname like lname + '%' this returns row 1 and 2... but not 3! (strange)

so how can i write a query that would return rows 1,2,3 and 4 since their last name is present in their password.

Thanks to all

Leroy L



leroyl
New Member
New Member

--
08 Dec 2008 01:37 PM
I would like to make a correction....


the query....
select * from mytable where fname like lname + '%'
returns row 1 and 3 NOT 2


Thanks
Leroy L

leroyl
New Member
New Member

--
08 Dec 2008 01:44 PM

GunneyK,

you are correct... i have some errors in my post...

the second row 4 should be row 5

any the query

select * from mytable where lname like Password + '%' returns only rows 1 and 3
select * from mytable where lname like '%' + Password + '%' returns tha same rows

but I see that switching lname and password in the query, as you sugested, fixes the problem and returns what is expected...

Thanks
Leroy L
You are not authorized to post a reply.

Acceptable Use Policy