Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to refer to one of the column inside a SQL query

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

You need to concatenate the ID into the comparison string:

select * 
from MY_TABLE 
where name not like concat('%.', id::text);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading