how to use LIKE with column name

Viewed 170421

Normally LIKE statement is used to check the pattern like data.

example:

select * from table1 where name like 'ar%'

My problem is to use one column of table with LIKE statement.

example:

select * from table1, table2 where table1.x is like table2.y%

Query above results error . how to use one column data in like query?

8 Answers

For SQLLite you will need to concat the strings

select * from list1 l, list2 ll 
WHERE l.name like "%"||ll.alias||"%";

for MySql you use like below,which is worked for me

SELECT * FROM table1, table2 WHERE table1.x LIKE (table2.y);

It takes table2's column values of y.

This works for me:

SELECT * FROM `mdl_user` WHERE `firstname` LIKE concat(lastname,'%') AND lastname != ''
Related