0

I am trying to search domain names ending in particular keywords. e.g. "car" would bring up buycar.com, but not carbuy.com.

So if my query is

SELECT * FROM domains WHERE LIKE '%car'

Will not show any results at all, obviously because the domains dont end in car, they end in .com, or .co, or something.

I think I need to do some sort of regex replace to search the domain, until the first .

Or whatever would do the equivalent of this in sql for php:

$pos = strpos($domain,'.');
$search = substr($domain,0,$pos);

So it would just search the actual domain without the TLD. Is this possible with sql?

1
  • You're missing the column name before LIKE. Commented Sep 7, 2017 at 0:54

2 Answers 2

4

How about using:

SELECT *
FROM domains
WHERE domain LIKE '%car.%'
Sign up to request clarification or add additional context in comments.

2 Comments

I only used "car" as an example, it could be anything
@Source . . . Then you would replace "car" with whatever you want to search.
0

You could remove characters like .com, .IR, .co after car and run own query.

Please try this:

SELECT *
FROM domains
WHERE 
REVERSE(SUBSTRING(REVERSE(domain),CHARINDEX('.',REVERSE(domain))+1,LEN(domain 
))) LIKE '%car'

if you don't remove that character and use Like '%car.%' maybe get some thing like this: car.site.com

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.