Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Avoid repetition in SQL Query
- Project ID | Project Name
- 1 | Project 1
- 2 | Project 2
- Enh ID | Enh Name | Project ID
- 1 | Enh Name 1 | 1
- 2 | Enh Name 2 | 1
- 3 | Enh Name 3 | 2
- Supp. ID | Supp. Proj Name | Project ID
- 1 | Supp Name 1 | 1
- 2 | Supp Name 2 | 2
- 3 | Supp Name 3 | 2
- select
- 'Enhancement: ' type_,
- p.name,
- e.name
- from
- project p,
- enhancement e
- where
- p.id =
- e.project_id
- UNION ALL
- select
- 'Support: ' type_,
- p.name,
- s.name
- from
- project p,
- support s
- where
- p.id =
- s.project_id;
- select
- p.name,
- e.name,
- s.name
- from
- project p,
- enhancement e,
- support s
- where
- p.id = e.project_id and
- p.id = s.project_id ;
- NAME NAME NAME
- --------------- --------------- ---------------
- Project one Enhancement 2 Support 1
- Project one Enhancement 1 Support 1
- Project two Enhancement 3 Support 2
- Project two Enhancement 3 Support 3
- TYPE_ NAME NAME
- ------------- --------------- ---------------
- enhancement: Project one Enhancement 1
- enhancement: Project one Enhancement 2
- enhancement: Project two Enhancement 3
- support: Project one Support 1
- support: Project two Support 2
- support: Project two Support 3
- select p.name as project_name1, // the 'as' might be superfluous ... not sure right now
- e.name as enhancement_name1
- from project as p, enhancement as e // whataver the desired jon condition is
- where p.id = e.project_id
- SELECT
- p.ProjectID,
- p.ProjectName,
- e.EnhName,
- s.SuppProjName
- FROM
- Project p
- LEFT JOIN EnhanchementPJT e ON p.ProjectID = e.ProjectID
- LEFT JOIN SupportTable s ON p.ProjectID = s.ProjectID
Add Comment
Please, Sign In to add comment