CREATE OR REPLACE FORCE VIEW "PLANTA_ALIAS" ("ID", "NAME", "TABLE_ID", "DB_POS", "SQL_FLAGS") AS 
select
	id,
	name,
	table_id, (
		select db_pos from planta_columns c2
		where c2.table_id = c1.table_id
		and c2.name = c1.name
		and c2.sql_flags < '2'
	) as db_pos,
	sql_flags
from planta_columns c1
order by c1.table_id asc, c1.db_pos asc;/
