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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.