skip to Main Content

I have some rows in an SQL table.
I have attributes as: id, name, etc.
Some of the names (in the name column) are built from some name ("xyz") and the id

id               name
333            regularName
555           somename.555  
666           myName.666

I want to select only rows that don’t include the id inside the name.

So my query was:

select * 
from MY_TABLE 
where name not like '%.id'

But it refer to id as a string

Is there a way to refer to one of the columns value inside the query?

2

Answers


  1. You need to concatenate the ID into the comparison string:

    select * 
    from MY_TABLE 
    where name not like concat('%.', id::text);
    
    Login or Signup to reply.
  2. select * from table
    where 
    not regexp_like(name, '.[0-9]+')
    
    • if regex is supported you can use this
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search