sql - Need help to get value from Oracle table -
i have 2 tables
table 1
name city -------------------- deep delhi manu atlanta raju panamacity
table 2
city ----- delhi
i wanted add together column called "country" in results final results like
name city country ------------------------------- deep delhi known manu atlanta unknown raju panamacity unknown
so if value of city column of first table match new column's value should have "known"
read on joins , case statements
select t1.name, t2.city, case t2.city null 'unknown' else 'known' end country table1 t1 left bring together table2 t2 on t1.city = t2.city
mockup:
select t1.name, t1.city, case when t2.city null 'unknown' else 'known' end country ( select 'deep' name, 'dehli' city dual union select 'manu' name, 'atlanta' city dual union select 'raju' name, 'panamacity' city dual) t1 left bring together (select 'dehli' city dual) t2 on t1.city=t2.city results in: name city country deep dehli known manu atlanta unknown raju panamacity unknown
sql oracle
No comments:
Post a Comment