I am surely just askewing my and statement here. I want to get a list of all tables that meet both conditions (but it returns 0). If I run each statement individually they each return multiple tables, but adding the and into the query 0 tables are returned (which I know is incorrect). What do I need to change to get this to execute successfully?
Works
select
table_name, column_name
from
information_schema.columns
where
column_name ILIKE 'Man%'
Works
select
table_name, column_name
from
information_schema.columns
where
column_name ILIKE 'sale%'
Returns 0 results
select
table_name, column_name
from
information_schema.columns
where
(column_name ILIKE 'man%'
and column_name ILIKE 'sale%')
order by
table_name asc
I want to return tables that have a column that begins with man
AND a column that begins with sale
only. Is there a way to achieve this result?
You could do something like this
select a.table_name,a.column_Name,b.column_Name from
(select table_name, column_name
from information_schema.columns
where column_name ILIKE 'Man%') a,
(select table_name, column_name
from information_schema.columns
where column_name ILIKE 'sale%')b
where a.table_name=b.table_name
order by a.table_name asc
As I said, I'm not familiar with postgresql so this may not work. :)
select a.table_name, a.column_name, b.column_name
from information_schema.columns a
join information_schema.columns b on a.table_name=b.table_name
where (a.column_name ILIKE 'man%'
AND b.column_name ILIKE 'sale%')
ORDER BY table_name ASC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.