Jump to content

Archived

This topic is now archived and is closed to further replies.

daiwa

SQL field like '%field2'

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--quoteo(post=353276:date=Mar 9 2006, 10:35 AM:name=lessthanthree)--][div class=\'quotetop\']QUOTE(lessthanthree @ Mar 9 2006, 10:35 AM) [snapback]353276[/snapback][/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?

Share this post


Link to post
Share on other sites
It's possible, it's easy.

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.