0

In Postgresql, I have 3 different tables A, B and C. A has a Problem column, B has a MedicalSolution column and C has a Diagnosis column.

I have a string and I want to check in these 3 tables if they contain that string. How can I do this?

Rodrigue
  • 3,617
  • 2
  • 37
  • 49
  • 1
    Unclear what you are asking. Please add sample data. – Tim Biegeleisen Jan 08 '19 at 06:23
  • 1
    Please provide schema, sample data and expected output. Not voted down me. – Suraj Kumar Jan 08 '19 at 06:26
  • Consider 3 columns from different 3 tables of type Varchar(50). I want to search name(eg.Belly) from a table which contains that name Belly. But the name of the columns is different table1 column Name1 , table2 column Name2 ,Table3 column Name3. – Mahesh Maske Jan 08 '19 at 06:30

1 Answers1

0

If I get correctly, You need something like this:

select exists( select 1 from Table1 where Name1 like '%Belly%' )
union all 
select exists( select 1 from Table2 where Name2 like '%Belly%' )
union all 
select exists( select 1 from Table3 where Name3 like '%Belly%' )

If you need data, then

select 'Table1' as table_name  /*needed columns here*/ from Table1 where Name1 like '%Belly%' 
union all 
select 'Table2' as table_name  /*needed columns here*/ from Table2 where Name2 like '%Belly%' 

remember that columns count and data types should match when use union all

Oto Shavadze
  • 40,603
  • 55
  • 152
  • 236