Jump to content


Photo

SQL field like '%field2'


  • Please log in to reply
4 replies to this topic

#1 daiwa

daiwa
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 05 March 2006 - 09:55 PM

I tried googling this but the search terms give off some very erratic results since it is very general.

What i am looking to do is something like this:

SELECT * FROM table WHERE `field1` LIKE %`field2`

this meaning that i want the rows where field 1 contains field2 at the end. (hence the %)
these being text fields.

Mysql 4.1

#2 daiwa

daiwa
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 09 March 2006 - 03:25 PM

anyone?

#3 lessthanthree

lessthanthree
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts
  • LocationUK

Posted 09 March 2006 - 03:35 PM

I don't think it can be done, although i may be wrong


SELECT * FROM table WHERE `field1` LIKE `field2`

works fine, but seeing as that is effectively the same as using = instead of like, it's pretty pointless.

I guess you will need to select the values prior to the LIKE query, and use values instead of field references.


call me a safe bet, i'm betting i'm not

#4 daiwa

daiwa
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 09 March 2006 - 03:38 PM

[!--quoteo(post=353276:date=Mar 9 2006, 10:35 AM:name=lessthanthree)--][div class=\'quotetop\']QUOTE(lessthanthree @ Mar 9 2006, 10:35 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I guess you will need to select the values prior to the LIKE query, and use values instead of field references.
[/quote]

is this even possible in pure sql(or mysql sql)? to go around assigning pseudo variables and the like?


#5 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 09 March 2006 - 07:25 PM

It's possible, it's easy.

SELECT * FROM table WHERE `field1` LIKE CONCAT('%', `field2`)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users