SQL Question

Here is my current script:

SELECT     Distinct  cost_code, pt.task_num, pjt.task_desc
FROM         projtran AS pt INNER JOIN
                      projtask AS pjt ON pt.proj_num = pjt.proj_num AND pt.task_num = pjt.task_num
WHERE     (pt.proj_num = @PARM0)


What I need is to append to that script so that it pulls  Distinct  cost_code, pt.task_num, pjt.task_desc not only from projtan but from another table as well - lc_lt_transaction

so if projtran has a distinct resultset of task_num:
100
100
200
300
300

and lc_lt_transaction task_num:
100
100
500 I would like my final result set to only have task_num:
100
200
300
500



LVL 5
thenrichAsked:
Who is Participating?
 
Shannon_LowderCommented:
This is a job for UNION.  IF you have two select queries that have the same number of columns, in this case cost_code, pt.task_num, pjt.task_desc from two separate queries, add the word UNION between them and the result will be the combination of the two queries.

With one important difference, you will only get the distinct list of both queries.  No duplicate rows will appear.  But, if one column in one row is different, and the other two have the same values, you will see both rows in your result set.

Make sense?

---
Shannon Lowder
Database Engineer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.