Chad Johnson
Chad Johnson

Reputation: 21895

SQL WHERE string LIKE field

I have a table tracking links structured as follows:

id
domain_name
traffic_count
enabled
created_at

Let's say I have a record with domain_name of "some-domain.com", and then let's say I want to find the record having that domain, except all I have to go by is a subdomain of that domain.

I essentially want to do this:

SELECT * FROM links 'subdomain.some-domain.com' LIKE %domain_name%"

How would I do this?

Upvotes: 2

Views: 9083

Answers (1)

RQDQ
RQDQ

Reputation: 15569

Updated (thanks to Chad Johnson):

SELECT * FROM links WHERE 'subdomain.some-domain.com' LIKE CONCAT('%', domain_name, '%')

Upvotes: 11

Related Questions