Heniam
Heniam

Reputation: 66

Find a substring in another column query?

I need to find a substring of a string in one table but different columns like

TableA
+-------+------------+
| name  | school     |
+-------+------------+
| jhon  | st.jhon    |
+-------+------------+
| mary  | st.mary    |
+-------+------------+
| mike  | st.patrick |
+-------+------------+

I need to find a substring such as a mary in st.mary

I tried to do select name, school from TableA where name like ('%',school,'%') but it's not working (getting an empty table).

Upvotes: -1

Views: 407

Answers (1)

Mureinik
Mureinik

Reputation: 312086

school contains name, so your like condition is backwards. Flip the columns and you should be OK:

SELECT name, school
FROM   tablea
WHERE  SCHOOL LIKE '%' || name || '%'

Upvotes: 2

Related Questions