Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL SELECT WHERE string ends with Column

I have this table in SQL Server 2012:

Id INT  DomainName NVARCHAR(150) 

And the table have these DomainName values

  1. google.com
  2. microsoft.com
  3. othersite.com

And this value:

mail.othersite.com 

and I need to select the rows where the string ends with the column value, for this value I need to get the row no.3 othersite.com

It's something like this:

DomainName Like '%value'  

but in reverse ...

'value' Like %DomainName 
like image 497
Mario Avatar asked Aug 20 '14 20:08

Mario


People also ask

What is %% in SQL query?

The SQL LIKE Operator There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters.


1 Answers

You can use such query:

SELECT * FROM TABLE1 WHERE 'value' LIKE '%' + DomainName 
like image 123
dotnetom Avatar answered Sep 23 '22 05:09

dotnetom