alias some columns names as one field in oracle's join select query

Posted by Marecky on Stack Overflow See other posts from Stack Overflow or by Marecky
Published on 2010-05-13T13:07:46Z Indexed on 2010/05/14 1:54 UTC
Read the original article Hit count: 238

Filed under:
|
|
|
|

Hi

We are developing something like a social networking website. I've got task to do 'follow me' functionality. In our website objects are users, teams, companies, channels and groups (please don't ask why there are groups and teams - it is complicated for me too, but teams are releated to user's talent)

Users, teams, channels, companies and groups have all their own tables.

I have a query which gets me all the follower's leaders like this

select
  --fo.leader_id,
  --fo.leader_type,
  us.name as user_name,
  co.name as company_name,
  ch.title as channel_name,
  gr.name as group_name,
  tt.name as team_name
from
  follow_up fo
left join users us
  on (fo.leader_id = us.id and fo.leader_type = 'user')
left join companies co
  on (fo.leader_id = co.user_id and fo.leader_type = 'company')
left join channels ch
  on (fo.leader_id = ch.id and fo.leader_type = 'channel')
left join groups gr
  on (fo.leader_id = gr.id and fo.leader_type = 'group')
left join talent_teams tt
  on (fo.leader_id = tt.id and fo.leader_type = 'team')
where
  follower_id = 83

I need to get all fields like:

  • user_name,
  • company_name,
  • channel_name,
  • group_name,
  • team_name

as one field in SELECT's product. I have tried to alias them all the same 'name' but Oracle numbered it. Please help :)

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about sql